note 76185 added to language.functions
| From: | deek at none dot net | Date: | Wed, 04 Jul 2007 04:43:50 +0000 |
| Subject: | note 76185 added to language.functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128217@lists.php.net to get a copy of this message | ||
Small Note:
While passing variables by reference ...
This first example does <NOT> work as expected....
function ChangeString(&$SuplyedString)
{
$SuplyedString = "BBB";
};
ChangeString($AAA='AAA');
print $AAA;
exit;
This will print 'AAA' ... and not the referenced value of 'BBB' as expected. It
seems that the = sign is interpreted after the function is executed and not before as one might
think?
Thus the fix is simple but more typing...
Same function but use ...
$AAA = 'AAA';
ChangeString($AAA);
print $AAA;
exit;
This will now print 'BBB' as it should.
Hope it saves you some debug time...
----
Server IP: 69.147.83.197
Probable Submitter: 74.96.6.33
----
Manual Page -- http://www.php.net/manual/en/language.functions.php
Edit -- https://master.php.net/note/edit/76185
Del: integrated -- https://master.php.net/note/delete/76185/integrated
Del: useless -- https://master.php.net/note/delete/76185/useless
Del: bad code -- https://master.php.net/note/delete/76185/bad+code
Del: spam -- https://master.php.net/note/delete/76185/spam
Del: non-english -- https://master.php.net/note/delete/76185/non-english
Del: in docs -- https://master.php.net/note/delete/76185/in+docs
Del: other reasons-- https://master.php.net/note/delete/76185
Reject -- https://master.php.net/note/reject/76185
Search -- https://master.php.net/manage/user-notes.php