Chovy’s Blog

Pass by Reference in PHP5

Thu, March 30, 2006 — Category: Open Source, Development

PHP5 has a Pass-by-reference notation: &$bar in line 3 as seen here in the parameter to a function bar(); Basically, this is just a point from the sub routine’s “$bar” back to the caller’s $foo. In this case, a change to the reference variable $bar is reflected in the main variable $foo.
“bar points to/references foo”
$bar […]

PHP5 has a Pass-by-reference notation: &$bar in line 3 as seen here in the parameter to a function bar(); Basically, this is just a point from the sub routine’s “$bar” back to the caller’s $foo. In this case, a change to the reference variable $bar is reflected in the main variable $foo.

“bar points to/references foo”
$bar => $foo;


1< ?
2 //pass by reference...
3 function bar(&$bar = NULL)
4 {
5 print "\tbar:" . $bar . "\n";
6 $bar = 'bar';
7 print "\tbar:" . $bar . "\n";
8 }
9
10 $foo = 'foo';
11 print "foo:" . $foo . "\n";
12 bar($foo);
13 print "foo:" . $foo . "\n";
14
15
16 ?>

Output:


foo:foo
bar:foo
bar:bar
foo:bar

Recommended reading: PHP 5 Objects, Patterns, and Practice

  • Post Pass by Reference in PHP5 to del.icio.us
  • Post Pass by Reference in PHP5 to digg
  • Post Pass by Reference in PHP5 to Furl
  • Add Pass by Reference in PHP5 to YahooMyWeb
  • Simpify!
  • Post Pass by Reference in PHP5 to shadows
  • Post Pass by Reference in PHP5 to Spurl
  • Post Pass by Reference in PHP5 to BuddyMarks
  • Submit Pass by Reference in PHP5 to Slashdot

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

 
Keyword Advertisers:
SEO Directory SEO Links Free Link Directory Shopping Submission Directory Gardening Tips Political Forum Search Engine Optimization Search Engine Marketing Audio Video Directory SEO Forum Web Development Blog Organic SEO Wiki Web Development Consulting

Learn more about purchasing keyword text link ads on this site.