Aslında, bu kod PHP 4 ile uyumlu olacak şekilde yazılır (Tim dedi - PHP 5, tüm nesneler referans olarak geçirilir) Ampersan PHP5'te işe yaramaz..
With PHP 4, all variables were passed by value.
If you wanted to pass it by reference, you had to declare a reference assignment :
$ref_on_my_object =& new MyObject();
Bu kod hala PHP 5 varsayılan yapılandırmayla kabul, ama yazmak daha iyi olduğu:
$ref_on_my_object = new MyObject(); // Reference assignment is implicit
For your second problem, the issue is "almost" the same...
Because PHP lets you declare function arguments (resp. types), and you can't do it for return values.
An accepted, but "not so good" practice is to avoid reference declaration within the function's declaration :
function foo($my_arg) {
// Some processing
}
ve referans ile çağrı ...
$my_var;
$result = foo( &$my_var );
// $my_var may have changed because you sent the reference to the function
İdeal beyanı gibi daha fazla olacaktır:
function foo( & $my_input_arg ) {
// Some processing
}
sonra, çağrı işareti kaybeder:
$my_var;
$result = foo( $my_var );
// $my_var may have changed because you sent the reference to the function