Skip to content

$this is not a **reference** to the called object. - #380

Closed
TysonAndre wants to merge 1 commit into
php:masterfrom
TysonAndre:this-is-not-a-reference
Closed

$this is not a **reference** to the called object.#380
TysonAndre wants to merge 1 commit into
php:masterfrom
TysonAndre:this-is-not-a-reference

Conversation

@TysonAndre

@TysonAndreTysonAndre commented Jan 23, 2021

Copy link
Copy Markdown
Contributor

It's the value of the called object.

Additionally, in php 7.1, it was no longer possible to reassign $this
indirectly through a reference.
https://wiki.php.net/rfc/this_var#disable_ability_to_re-assign_this_indirectly_through

Even in php 7.0, I'd think it would initially be more like a value
(that references can be created from) than
a reference, but I may be misunderstanding what this means or what $this
did in php 5 or older.

(The manual dropped support for documenting php 5's behavior months ago, anyway)

@TysonAndre
TysonAndreforce-pushed the this-is-not-a-reference branch from 1bd2900 to bcf9c8fCompareJanuary 23, 2021 16:28
@Girgias

Copy link
Copy Markdown
Member

Thanks for catching this, it might make sense to move the documentation of $this to the OOP section or the predefined variables section.

It's the value of the called object.
Additionally, in php 7.1, it was no longer possible to reassign $this
indirectly through a reference.
Even in php 7.0, I'd think it would initially be more like a value
(that references can be created from) than
a reference, but I may be misunderstanding what this means or what $this
did in php 5 or older.
@TysonAndre
TysonAndreforce-pushed the this-is-not-a-reference branch from bcf9c8f to d0a40a9CompareJanuary 23, 2021 17:56
@TysonAndre

Copy link
Copy Markdown
ContributorAuthor

It already has documentation in https://www.php.net/manual/en/language.oop5.basic.php - which turns out to also need to be updated

@cmb69

Copy link
Copy Markdown
Member

I think this wording stems from PHP 4, where $this had to had reference semantics. The term "value" appears to be right as of PHP 5.0.0, but we should check the manual. E.g. https://www.php.net/manual/en/language.operators.assignment.php#language.operators.assignment states:

An exception to the usual assignment by value behaviour within PHP occurs with objects, which are assigned by reference. Objects may be explicitly copied via the clone keyword.

It seems to me that we should clearly define the "value of objects" meaning the "object handle" (or something like that), opposed to the values of the objects properties (cf. ==).

@Girgias

Copy link
Copy Markdown
Member

This is documented here: https://www.php.net/manual/en/language.oop5.references.php

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@TysonAndre@Girgias@cmb69