Re: Idea: Pure Functions in PHP

From: Date: Fri, 25 Sep 2026 20:02:39 +0000
Subject: Re: Idea: Pure Functions in PHP
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-132644@lists.php.net to get a copy of this message
Hey Pedro, On Fri, 25 Sept 2026 at 21:59, Pedro Veloso <contatopedrohalves@gmail.com> wrote: > ```php > class Ha { > private int $a = 1; > > #[Pure] > public function getA(): int { > return $this->a; > } > } > > new Ha()->getA(); // Fatal error: pure method Ha::getA() accesses $this. > ``` > Overall, I would also like to see functional purity in PHP, but a n instance method is just a function with an implicit additional $this argument, and it is pure if it causes no state mutation. Marco Pivetta https://mastodon.social/@ocramius https://ocramius.github.io/

« previous php.internals (#132644) next »