As long as $var1 and $var2 are primitive types and not objects, then $var2 is not a pointer to $var1 (however, I have read that PHP will store it internally with a pointer until the value of $var2 is changed to something else.)
If you need $var2 to be a reference to $var1 you can do this:
$var2 = & $var1;
Objects are always passed by reference (in PHP 5.x.) Trying to pass an object by reference produces in error in php 5.x.
are you sure about this? I have code snippet with a mysqli object in $var1 and I have put $var2 equal to $var1. I can perform query's through both variables but If i close the connection on of them the other is also disconnected and I get an error while performing a query. Wouldn't that mean that the variables are pointers and that the language is built with the "one memory slot, several pointers"-way?
What exactly is the use of "&"? Thank you for taking your time :)
are you sure about this? I have code snippet with a mysqli object in $var1 and I have put $var2 equal to $var1. I can perform query's through both variables but If i close the connection on of them the other is also disconnected and I get an error while performing a query. Wouldn't that mean that the variables are pointers and that the language is built with the "one memory slot, several pointers"-way?
What exactly is the use of "&"? Thank you for taking your time :)
Yes, as you stated, $var1 was an object so assigning $var1 to $var2 simply made $var2 a reference to $var1. So yes, $var2 is basically a pointer to the same object.
The & reference operator is normally used in a function declaration to have a parameter "pass by reference." This lets a function directly modify one of its parameters.
function example(& $p1, $p2)
{
$p1 += 10; // p1 is a reference to $a and modifies the variable $a.
return $p1+$p2;
}
$a = 5;
$b = 2;
$sumplus10 = example($a, $b);
echo $a.','.$b.', '.$sumplus10;
// $a now equals 15 instead of 5.
This is just a quick (and rather useless example) of how pass by reference works.
To be honest I don't use it very much since it makes code harder to debug. Also, php already uses some optimization tricks to make unnecessary to do this for performance reasons.
APLX is a very complete implementation of the APL programming language from MicroAPL. The company stopped producing it in 2016 and it has been taken over by Dyalog. While Dyalog ...