note 42192 added to language.references
| From: | thenewparadigm at hotmail dot com | Date: | Fri, 07 May 2004 04:33:04 +0000 |
| Subject: | note 42192 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69294@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42192
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42192&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42192&report=yes
Search -- http://master.php.net/manage/user-notes.php