开发者

Is it possible to turn off that method with the same name as class name is constructor?

开发者 https://www.devze.com 2023-02-05 18:24 出处:网络
Is it possible to turn off that method with the same name as class name is constructor? In PHP. Here is an example...

Is it possible to turn off that method with the same name as class name is constructor? In PHP.

Here is an example...

class Foo {
    function foo() { // This would be the constructor, but I don't want to... ='(
        echo 'I was here!';
    }
}

$foo = new Foo;

PHP v5.3.2 on Ubuntu开发者_StackOverflow社区.


Yes it is possible. According to the __construct Documentation, it will not resolve that type of constructor for namespaced classes as of 5.3.2 (your version). So as long as your class is namespaced, it won't behave that way.

namespace My;
class Foo {
    function foo() {
        echo 'I was here!';
    }
}
$foo = new Foo; // won't echo
0

精彩评论

暂无评论...
验证码 换一张
取 消