开发者

Do these two PHP OOP syntaxes yield the same result?

开发者 https://www.devze.com 2023-03-21 17:02 出处:网络
In PHP, is: $objectVar = someClassName::someFunction($var); the same as: $object =开发者_如何学JAVA new someClassName();

In PHP, is:

$objectVar = someClassName::someFunction($var);

the same as:

$object =开发者_如何学JAVA new someClassName();
$objectVar = $object->someFunction($var);


No.

$objectVar = someClassName::someFunction($var);

Here, someFunction is a static method; i.e. it belongs to a class, not an object.

$object    = new someClassName();
$objectVar = $object->someFunction($var);

In this code, it is an instance method that should be accessed through an object.

The result could be the same, but the handle used to call the method is different.

0

精彩评论

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