A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearAre there pointers in php? - page 1
User InfoPosts
Are there pointers in php?#1
What does this code mean? Is this how you declare a pointer in php?

$this->entryId = $entryId;

posted date: 2009-04-13 19:20:00


Re: Are there pointers in php?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-13 19:20:01


Re: Are there pointers in php?#3
entryId is an instance property of the current class ($this)And $entryId is a local variable

posted date: 2009-04-13 19:22:00


Re: Are there pointers in php?#4
That syntax is a way of accessing a class member. PHP does not have pointers, but it does have references. The syntax that you(re quoting is basically the same as accessing a member from a pointer to a class in C++ (whereas dot notation is used when it isn(t a pointer.)

posted date: 2009-04-13 19:23:00


Re: Are there pointers in php?#5
are you sure gidforums.com/t-3235.html?

posted date: 2009-04-13 19:55:00


Re: Are there pointers in php?#6
To answer the second part of your question - there are no pointers in PHP. When working with objects, you generally pass by reference rather than by value - so in some ways this operates like a pointer, but is generally completely transparent. This does depend on the version of PHP you are using.

posted date: 2009-04-13 20:10:00


Re: Are there pointers in php?#7
Variable names in PHP start with $ so $entryId is the name of a variable.$this is a special variable in Object Oriented programming in PHP, which is reference to current object.-> is used to access an object member (like properties or methods) in PHP, like the syntax in C++.so your code means this:Place the value of variable $entryId into the entryId field (or property) of this object.The & operator in PHP, means pass reference. Here is a example:$b=2;$a=$b;$a=3;print $a;print $b;// output is 32$b=2;$a=&$b; // note the & operator$a=3;print $a;print $b;// output is 33In the above code, because we used & operator, a reference to where $b is pointing is stored in $a. So $a is actually a reference to $b.In PHP, arguments are passed by value by default (inspired by C). So when calling a function, when you pass in your values, they are copied by value not by reference. This is the default IN MOST SITUATIONS. However there is a way to have pass by reference behaviour, when defining a function. Example:function plus_by_reference( &$param ) { // what ever you do, will affect the actual parameter outside the function $param++;}$a=2;plus_by_reference( $a );echo $a;// output is 3There are many built-in functions that behave like this. Like the sort() function that sorts an array will affect directly on the array and will not return another sorted array.There is something interesting to note though. Because pass-by-value mode could result in more memory usage, and PHP is an interpreted language (so programs written in PHP are not as fast as compiled programs), to make the code run faster and minimize memory usage, there are some tweaks in the PHP interpreter. One is lazy-copy (I(m not sure about the name). Which means this:When you are coping a variable into another, PHP will copy a reference to the first variable into the second variable. So your new variable, is actually a reference to the first one until now. The value is not copied yet. But if you try to change any of these variables, PHP will make a copy of the value, and then changes the variable. This way you will have the opportunity to save memory and time, IF YOU DO NOT CHANGE THE VALUE.So:$b=3;$a=$b;// $a points to $b, equals to $a=&$b$b=4;// now PHP will copy 3 into $a, and places 4 into $bAfter all this, if you want to place the value of $entryId into (entryId( property of your object, the above code will do this, and will not copy the value of entryId, until you change any of them, results in less memory usage. If you actually want them both to point to the same value, then use this:$this->entryId=&$entryId;

posted date: 2009-04-13 20:20:00


Re: Are there pointers in php?#8
those are references, they're slightly different

posted date: 2009-04-13 20:28:00


Re: Are there pointers in php?#9
see: php.net/manual/en/language.references.php#82791

posted date: 2009-04-13 20:30:00


Re: Are there pointers in php?#10
PHP passes Arrays and Objects by reference (pointers). If you want to pass a normal variable Ex. $var = (boo(; then use $boo = &$var;.

posted date: 2009-04-13 20:39:00


Re: Are there pointers in php?#11
uhhhhhhhhh, no. $ php -r '$x = 1; > $y = array(&$x); > var_dump($y); > $x = 2; > var_dump($y); > $y[0] = 3; > var_dump($x);' //// Output: array(1) { [0]=> &int(1) } array(1) { [0]=> &int(2) } int(3)

posted date: 2010-12-14 10:14:00


Re: Are there pointers in php?#12
this is how you initiate a variable, -> is equivalent to the dot operator in java

posted date: 2012-04-28 11:14:00


select page: « 1 2...»
Copyright ©2008-2017 www.momige.com, all rights reserved.