php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29018 function arguments 'null' and staticval with n passing by reference
Submitted: 2004-07-05 19:07 UTC Modified: 2004-08-04 14:33 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: none at space dot com Assigned: vrana (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.6 OS: any
Private report: No CVE-ID: None
 [2004-07-05 19:07 UTC] none at space dot com
Description:
------------
proper reference documentation missing on how to switch from 'call-time call-by-reference' to 'call-by-reference'.


with more and more ISP's upgrading php from versions prior the deprecated 'call-time call-by-reference' to newer versions, more and more people get utterly frustrated searching solutions to fix their codes or libs for the two situations below. 

especially passing 'no object' or null to a class has become critical and there is no clear statement in the documentation of (references explained) on what logic the guys that deprecated the the 'call-time' functionality had in mind to compensate for that lack of functionality.

i think it's about time you post the concept and solution of this change somewhere prominently. 











Reproduce code:
---------------
function foo (& $var){
 if (is_null($var)){return 0};
 return(1);
}

#call now
foo($somevar);  #will work
foo('');        #will not work (how to do this properly?)
foo(1);         #will not work (obviously)



Expected result:
----------------

>1
>0
>0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-07 11:55 UTC] jform at helmsdeep dot org
I agree totally! We used to be able to do the following:

myfunc(& $someobj);   #and
myfunc('');           #this, if nothing passed

function foo ($obj){
  if(is_null($obj)){...};
  ...
}

At this point we have to pre-check everything and do some massive recoding! What is an easy solution for this or waht were you thinking when chaning this? How do I pass 'nothing' now?
 [2004-07-07 11:57 UTC] jform at helmsdeep dot org
above: sorry, typo:

   function foo ($obj){

should obviously be 

   function myfunc ($obj){

i was copying...
 [2004-07-19 14:24 UTC] jsabre at jjsbr dot tv
I was wondering about this too... how can you deprecate this and not tell the community what is going on? I found only very little info about this issue out there. But meny people seem to truggle with it.
 [2004-07-28 21:58 UTC] vrana@php.net
Possible solution:

function foo (& $var){
 if (is_null($var)){return 0};
 return(1);
}

$somevar = null;
foo($somevar);

Possible workarounds:

allow_call_time_pass_reference can be set on per directory basis.

@ can be added before function call (with side-effect of not displaying any errors of course)

There's no other solution AFAIK.
 [2004-08-02 15:44 UTC] josh at vodafone dot de
Workarounds? How elegant!  :P  

You got to be kidding, right? We were talking improvements!

The workarounds are known by know. Is there nothing more elegant like 


foo(NULL);
 [2004-08-03 09:50 UTC] vrana@php.net
Along workarounds I mentioned also one solution. I'll document that. foo(NULL) is maybe the most elegant solution in your eyes however this manner is deprecated :-(.

I'm not sure why it's deprecated (probably for performance reasons) so I can't explain why it's deprecated.
 [2004-08-03 15:21 UTC] josh at vodafone dot de
Ok. No pun intended. 

It's just so odd that we're stuck in a situation where a good solution has changed to something agreeably 
  - not really elegant 
and
  - the reason for the change cannot be explained by the php team itself. 

I guess no further comment is needed.
 [2004-08-04 14:33 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Passing arguments by reference at function call time was deprecated for code cleanliness reason. Function can modify its argument in undocumented way if it didn't declared that the argument is passed by reference. To prevent side-effects it's better to specify which arguments are passed by reference in function declaration only."

josh at vodafone: I like you too :-).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 19:00:02 2025 UTC