note 42192 deleted from language.references by nikic

From: Date: Sat, 23 Apr 2016 17:08:00 +0000
Subject: note 42192 deleted from language.references by nikic
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205308@lists.php.net to get a copy of this message
Note Submitter: thenewparadigm at hotmail dot com ---- one very useful aspect for reference that i don't think i saw documented was the ability to skip a few steps with objects stored in objects. for example: assuming the object structure is correctly constructed (and mind you i haven't tried this in php, but it does work in most other high-end programming languages), instead of using this structure to get a variable/function //start $obj1 -> obj2 -> obj3 -> varX = 0; $obj1 -> obj2 -> obj3 -> varY = 0; $obj1 -> obj2 -> obj3 -> functionX(); $obj1 -> obj2 -> obj3 -> functionY(); //end you can use this method: //start $tempObj = & $obj1 -> obj2 -> obj3; $tempObj -> varX = 0; $tempObj -> varY = 0; $tempObj -> functionX(); $tempObj -> functionY(); //end note, if you want to use a shortcut variable to modify the original object you must include the ampersand (&) to reference the variable, otherwise if you used this line of code //start $tempObj = $obj1 -> obj2 -> obj3; //end any changes you make to $tempObj will not change the original object and may compromise the object structure, not to mention that it takes up extra memory. however, if you are just using the shortcut variable for read-only purposes, not using a reference wont cause any problems. another alternative in programming languages is the 'with' structure as seen below //start with($obj1 -> obj2 -> obj3) { varX = 0; varY = 0; functionX(); functionY(); } //end however, i don't expect this will work because as far as i've seen the 'with' structure is not supported in php.

« previous php.notes (#205308) next »