Re: OOP::problem?
| From: | Jack Kline | Date: | Wed, 02 Apr 2003 00:24:35 +0000 |
| Subject: | Re: OOP::problem? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4580@lists.php.net to get a copy of this message | ||
Bertrand,
Thanks for the example. This is truely scarry. I come from a Java OOP
background and one of the the key atributes of OOP is encapsulation and for
now PHP is limited to programmer obeyance of convention. I think PHP would
greatly benefit from adhering to some standard OOP definitions:
encapsulation, polymorphism, interfaces, etc... Right now, none of these
features are enforceable... but I understand PHP5 promises some tighter
restrictions...what you've documented below is just another convention to
avoid...
"Bertrand Mansion" <bmansion@mamasam.com> wrote in message
news:BAAF890D.626E%bmansion@mamasam.com...
<matthias.nothhaft@gmx.de> wrote :
> Hi all,
>
> this is my first mail to this list,
> but I don't know if this is the right one
> for my problem, because it is not really depending
> on pear, but I hope there are some php devs, who
> can help me?
>
> Ok, I have a little idea to use it in PEAR...
> I promise I'll tell it in my next posting ;-)
>
>
> Take a look at my example:
>
> <?php
>
> class a
> {
> function test($s)
> {
> $this->myvar = $s;
> }
> }
>
> class b
> {
> var $myvar;
>
> function b($s)
> {
> a::test($s);
>
> echo $this->myvar;
> }
> }
>
> $b =& new b("hello world!");
>
> ?>
>
> The output is... "hello world!"
>
> Now my "problem": Is this a bug or a feature,
> that I can access to class variables of any object
> by using $this->anyvar in a class::function() ?
I think it should be considered as a bug, not a feature so don't rely on it.
You might get some better (or more confuse) advices in the php-dev archives.
Bertrand Mansion
Mamasam