php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #16738 confusing explanation of assigning by reference
Submitted: 2002-04-22 16:59 UTC Modified: 2002-04-22 18:47 UTC
From: benh at uk2 dot net Assigned: alindeman (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.2.0 OS: n/a
Private report: No CVE-ID: None
 [2002-04-22 16:59 UTC] benh at uk2 dot net
<?php
$foo = 'Bob';              // Assign the value 'Bob' to $foo
$bar = &$foo;              // Reference $foo via $bar.
$bar = "My name is $bar";  // Alter $bar...
echo $foo;                 // $foo is altered too.
echo $bar;
?>

Why do '$bar = "My name is $bar";'? And then do 'echo $foo' *before* you 'echo $bar'? The point you're trying to make is surely expressed  better like this:

<?php
$foo = 'Bob';              // Assign the value 'Bob' to $foo
$bar = &$foo;              // Reference $foo via $bar.
$bar = "Dave";  // Alter $bar...
echo $bar;                
echo $foo; // $foo is altered too.
?>


Clearer for the newcomer to programming, ne?

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-22 17:21 UTC] alindeman@php.net
assigned to myself

 [2002-04-22 18:47 UTC] bs@php.net
This bug has been fixed in CVS.
 [2003-03-07 03:09 UTC] jharders at tricept dot de
I've downloaded the latest PHP5-win-binary-package,
assuming that bug will would fixed, but it is'nt?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Aug 16 01:01:28 2024 UTC