Joedel
Joedel

Reputation: 1

What's the difference between this two PHP object instantiation types?

I wonder about the differences of this PHP instantiation type.

$object = new MyClass();

vs

$this->object = new MyClass();

What's the difference between this two?

Upvotes: 0

Views: 105

Answers (1)

fyr
fyr

Reputation: 20859

The first one instantiates an object of MyClass to a variable object in variable-scope.

The second one instantiates an object of MyClass in another(not necessarily a different one) class object attributes value.

Upvotes: 1

Related Questions