By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

help with passing a null argument as reference, please

P: n/a


please help! does anyone know the proper way to pass null as an
argument to a function that expects a reference?
i have a function that receives an object and attaches it to
another object in a hierarchical node-like fashion. it returns the
new node:

$level5 =& $myNodes->addObj($level4, $data);

all works fine, but for the case of the top level node, where i'd like
to pass 'null' or 'no object' as the node to attach to:

$level0 =& $myNodes->addObj('', $data);

the function addObj() knows what to do in that case, but my problem is
that i cannot pass 'null', because that's not a reference and throws
[Cannot pass parameter 1 by reference in...]. how can i get around that?
i read that i could to

$dummy = null;
$level1 =& $myNodes->addObj($dummy, $data);

but that's far from elegant. is there any other way to handle this? i
searched, but couldn't really find a proper solution to this. pre-4.3.6
i was actually able to do it with a Call-time-pass-by-reference as

$level5 =& $myNodes->addObj(& $level4, $data);
$level0 =& $myNodes->addObj('', $data);

which worked beautifully but is deprecated.... [grrrr]
any hint is appreciated!!!!


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Allan Rydberg wrote:
please help! does anyone know the proper way to pass null as an
argument to a function that expects a reference?
i have a function that receives an object and attaches it to
another object in a hierarchical node-like fashion. it returns the
new node:

$level5 =& $myNodes->addObj($level4, $data);

all works fine, but for the case of the top level node, where i'd like
to pass 'null' or 'no object' as the node to attach to:

$level0 =& $myNodes->addObj('', $data);


$level0 =& $myNodes->addObj(NULL, $data);

--
Andrew @ Rockface
np: (Winamp is not active ;-)
www.rockface-records.co.uk
Jul 17 '05 #2

P: n/a


no! NULL itself cannot be interpreted as a REFERENCE[!!!] and you'd
get: [Fatal error: Cannot pass parameter 1 by reference...]
that's the whole point....

and if you try this at home, use the4 following to be fully
compliant:

function &addObj(& $obj,$data){
#----------^ !!!!!
...
...
return $some_new_obj;
}

Andrew @ Rockface wrote:
Allan Rydberg wrote:
please help! does anyone know the proper way to pass null as an
argument to a function that expects a reference?
i have a function that receives an object and attaches it to
another object in a hierarchical node-like fashion. it returns the
new node:

$level5 =& $myNodes->addObj($level4, $data);

all works fine, but for the case of the top level node, where i'd like
to pass 'null' or 'no object' as the node to attach to:

$level0 =& $myNodes->addObj('', $data);

$level0 =& $myNodes->addObj(NULL, $data);


Jul 17 '05 #3

P: n/a
Allan Rydberg wrote:
no! NULL itself cannot be interpreted as a REFERENCE[!!!] and you'd
get: [Fatal error: Cannot pass parameter 1 by reference...]
that's the whole point....

and if you try this at home, use the4 following to be fully
compliant:

function &addObj(& $obj,$data){
#----------^ !!!!!
...
...
return $some_new_obj;
}


Sorry, I missed the part about 'reference'.
You're right and I have no idea how to get around a function expecting a ref
and getting a NULL.

--
Andrew @ Rockface
np: (Winamp is not active ;-)
www.rockface-records.co.uk
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.