Re: Methods which auto-return the class instance

From: Date: Sat, 24 Dec 2022 10:52:13 +0000
Subject: Re: Methods which auto-return the class instance
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-119208@lists.php.net to get a copy of this message
On 23 December 2022 13:29:07 GMT, Claude Pache <claude.pache@gmail.com> wrote: >> Yes but declaring self is more strict than >> object. >> And talking about the word itself... Declaring to return (your-)¤³PªfÉB»Ã� >> (8°Rself but you could return someone-else of the same type as you. >> But it is ok, it refers to the class name not the instance. just semantic. >> > > >It is not about being less or more restricted, it is about being plainly ambiguous. Another big advantage of "return $this" is that it can't affect any existing code. Granted, a function marked :self or :static which currently fails to return would be a runtime error, but changing that error into an implicit return $this could be very dangerous. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#119208) next »