note 35322 deleted from language.oop by didou
| From: | didou@php.net | Date: | Fri, 03 Oct 2003 16:35:08 +0000 |
| Subject: | note 35322 deleted from language.oop by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57755@lists.php.net to get a copy of this message | ||
Note Submitter: jim@thestapletons.org
----
Here's something interesting I found that might be useful:
How to access parts of a class object used in another class:
class foo
{
var $a = "blah";
function blah()
{
echo "$a";
}
/*...*/
}
class bar
{
var $f = new foo();
function bad1()
{
$this->f->blah(); //look at the pretty parse/undefined variable error!
}
function bad2()
{
($this->f)->blah(); //another lovely error
}
function bad1()
{
{$this->f}->blah(); //more errors
}
function bad1()
{
$var = "f";
$this->$var->blah(); //you guessed it, error here.
}
function not_bad()
{
$f =& $this->f;
$f->blah; //echo: "blah": No error, I'm dissapointed...
}
/*...*/
}
So, if you want to call a function or access a variable of an encapsulated class, you should make a
reference to that specific class object in the function that uses it. If someone has a better idea
or method, please post, I'd appreciate it.