From:             [EMAIL PROTECTED]
Operating system: All
PHP version:      4.2.3
PHP Bug Type:     Feature/Change Request
Bug description:  Call Time pass by Reference should not be removed

In my opinion I do not think depreciating and removing the Call Time Pass
by Reference feature of PHP is a good idea. There are a number of valid
reasons to use this feature, to which this feature is the only solution.
While programming a very large web database application for my employer,
I've found where this feature is extremely useful. Yet when I've upgraded
to new versions of PHP I've come to find that it is depreciated. 

My example. In this application I've written a series of classes, I call
them XElements. Each XElement is essentially a class that is dedicated to
an XHTML 1.0 element.  So for example, I have an XForm, XTable, XTd, XTr,
etc.  They all inherit the XElement class. The XElement class has a number
of methods that are useful. The most important two are add() and draw(). 


The add() method takes one argument. This argument is then put into an
array variable of the object, maintaining the order by call to add().  So
each time I call add() it adds this argument to the end of the array. What
are these arguments? They are the nested CDATA.  Consider this:

<form ...>
    <p>
        Name
        <input ... />
        Password
        <input ... />
     </p>
</form>

The way my code above would work is like this.

$myForm =& new XForm();
$myP =& new XP();
$myForm->add(&$myP);

$myP->add("Name");

$myInput1 =& new XInput();
$myP->add(&$myInput1);

$myP->add("Password");

$myInput2 =& new XInput();
$myP->add(&$myInput2);

$myForm->draw();

This is partially pseudo, since my real constructors have many arguments
for attributes of the XHTML code, I've left them out of this example for
clarity. Now with that in mind, onto draw().

The draw() method does one simple thing. It iterates through the array of
CDATA, and writes it out either by 1) if it's a string, echo it, 2) if
it's an object, assume its an XElement and call that XElement's draw().
You can see how it then works. draw() manages the closing tags, and knows
which tags are allowed CDATA and which are not thus using /> instead of >
as well. 

Now, with the above example we can see where Call Time Pass by Reference
comes into play.  If in the first part of my code, I did
$myForm->add($myP); instead of $myForm->add(&$myP); that would create a
copy of $myP and pass it to add().  Then any calls to $myP after that
add() won't reflect the $myP stored in the CDATA Array.  I could modify
the declaration of add() so that it takes a reference for the argument,
function add(&$arg) { ... }.  However, then I go to do $myP->add("Name");,
this would happen:

Fatal error: Cannot pass parameter 1 by reference

So what once would originally have only taken one function, would require
two if Call Time Pass by Reference was removed. I'd have to create one
function to add non-references, and one to add references.  One could say
I could have a function for adding string CDATA, and one for adding
XElements, however there comes a time when I don't want to add a reference
to a XElement, but rather have it store a copy. This may come into play if
say I wanted to construct one XInput then change a field in the object and
re-add it over and over, then I would omit the Call Time Pass by
Reference.

>From what I can gather, removing Call Time Pass by Reference was suppose
to make it easier to read code, however if I have to add an additional
function to manage non-references, I'm don't see the benefits anymore.
 


-- 
Edit bug report at http://bugs.php.net/?id=21123&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=21123&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=21123&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=21123&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=21123&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=21123&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=21123&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=21123&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=21123&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=21123&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=21123&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21123&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=21123&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=21123&r=isapi

Reply via email to