note 114413 deleted from language.references.whatare by cmb

From: Date: Thu, 06 Aug 2015 11:00:02 +0000
Subject: note 114413 deleted from language.references.whatare by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203276@lists.php.net to get a copy of this message
Note Submitter: mike at eastghost dot com ---- If I make a function, using PHP 5.5.5: function recurring_mailer_form( $form, $form_state ) {} Is it the same as: function recurring_mailer_form( $form, & $form_state ) {} ? ---------- NO Using php 5.5.x+ If you pass an object as usual (ie, without the ampersand), you can (only) alter the object's state (properties) (but not change the whole obj into a new obj) $obj is an instance of the class Test which contains a member variable called hello: function modify($obj) { $obj->hello = 'world (modified)!'; } $obj->hello = 'world'; modify($obj); var_dump($obj->hello); // outputs "world (modified!)" ---------- Now, using the same code but assigning another value to $obj instead modifying the object's state results in no modification: function modify($obj) { $obj = 42; } var_dump($obj->hello); // outputs "world" ---------- Only accepting the parameter explicitly as a reference gives us the ability to completely change the variable's contents: function modify(&$obj) { $obj = 42; } var_dump($obj); // outputs "42" ---------- http://stackoverflow.com/questions/19847781/do-i-need-to-use-the-ampersand-in-php-5-5-x-and-above-anymore

« previous php.notes (#203276) next »