Re: :: abused for static method call
| From: | Teodor Cimpoesu | Date: | Sun, 25 Jun 2000 20:10:02 +0000 |
| Subject: | Re: :: abused for static method call | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3024@lists.php.net to get a copy of this message | ||
Hi Ulf!
On Sun, 25 Jun 2000, Ulf Wendel wrote:
> Hi!
>
> I'm surprised that the following code works and prints 8:
cool discovery :)
>
> <?php
> class foo {
>
> var $bar = 0;
>
> function foo() {
>
> $this->bar = 8;
> prints $this->bar;
>
> }
> }
> foo::foo()
> ?>
actually if you stick a var_dump($this) before and after the
assignement you'll see NULL and object(...) so it looks like
a change to $this creates a new object, but where is it?
is it a memory leak or it is destroyed at once?
> Why can I use "::" outside a class? Looks like a side effect or is this
> intented. I don't not belive that it is, right?
>
> If it's so why can the foo constructor access a property using the
> pseudo object $this it can't access another method using $this? This
> will cause an error:
>
> <?php
> class foo {
>
> function foo() {
> $this->bar();
> }
>
> function bar() {
> }
>
> }
>
> foo::foo();
> ?>
I tried that too, and if I stick a $this = new foo() before
calling bar() it works, cool :)
Is this behaviour permanent?
-- teodor