Jump to content

An Odity


trq

Recommended Posts

Here is an oddity I just accidentally bumped into.

 

#!/usr/bin/php
<?php

class foo {

    public function bar() {
        echo "this is bar";
    }   

    public function callBar() {
        $this->bar();
    }   

}

class someother {
    public function callFooBar() {
        echo foo::callBar();
    }   
}

$so = new someother;
$so->callFooBar();

 

This means you can now do....

 

#!/usr/bin/php
<?php

class foo {

    public function bar() {
        echo "this is bar";
    }   

    public function callBar() {
        $this->bar();
    }   

}

class someother {
    public function callFooBar() {
        echo foo::callBar();
    }

    public function bar() {
        echo "this is someother bar";
    }   
}

$so = new someother;
$so->callFooBar();

 

Not sure it's useful, or just weird behaviour.

Link to comment
https://forums.phpfreaks.com/topic/247990-an-odity/
Share on other sites

Whoah, that is tricky. IMO that shouldn't happen, but what do I know :)

 

On output this is what I see:

Strict Standards: Non-static method foo::callBar() should not be called statically, assuming $this from incompatible context in [..]foo.php on line 17

this is someother bar

 

Good, at least PHP tells you something is wrong

Link to comment
https://forums.phpfreaks.com/topic/247990-an-odity/#findComment-1276412
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.