Ricalsin
Ricalsin

Reputation: 940

Do these two PHP OOP syntaxes yield the same result?

In PHP, is:

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

the same as:

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

Upvotes: 0

Views: 75

Answers (1)

Null Head
Null Head

Reputation: 2941

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.

Upvotes: 1

Related Questions