473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with passing a null argument as reference, please



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
3 5001
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sam pal | last post by:
I have the following programs and please clear my doubts. Passing the value by reference is same as pointer by reference. Is this true? What is the difference between display and display2? How...
9
by: SB | last post by:
Ok, very simple problem. I'm trying to update a value by calling a function using pass by reference, but it does not update the value. In short, the value I'm trying to update is balance, which is...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
17
by: LP | last post by:
Hello, Here's the scenario: Object A opens a Sql Db connection to execute number of SqlCommands. Then it needs to pass this connection to a constructor of object B which in turn executes more...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.