JeanDavidD
JeanDavidD

Reputation: 299

PHP: What does `array(&$this)` mean?

In PHP, I would like to know what array(&$this) means.

Upvotes: 10

Views: 13002

Answers (3)

xenon
xenon

Reputation: 1425

This is creating an array with a single element. The element is a reference to the object from which it is executed it. For more information see the documentation on passing by reference.

Upvotes: 0

Jon
Jon

Reputation: 437474

It's a construct that initializes an array which contains one element: a reference to the object the array is initialized in. Inside every class, you can refer to the "current" instance using $this.

Upvotes: 13

Anders Lindahl
Anders Lindahl

Reputation: 42890

Its PHPs pass by reference construction. Typically this means that a reference to the parameter is passed to the function instead of a copy of the value, so that modifications inside the function affect the object.

Upvotes: 6

Related Questions