> I cannot really assess how big of a hassle it would be, but what I personally > think that it look nice is something like this: > > ``` > class Verification > { > public function __construct(private string $id) {} > > public function getId(): string > { > return $this->id; > } > > public static function getIdAbs(self $instance) { > return abs($instance->id); > } > } > > $items = [new Verification(“1”), new Verification(“2”))]; > > array_map($$->getId(…), $items); > > array_map($$::getIdAbs(…), $items); > ``` > > This way the class does not have to be imported. Later one might be able to > add additional parameters even. > > ``` > class Verification > { > // […] > > public static function getIdAbs(self $instance, array $idMap) { > // do something with the $idMap > return abs($instance->id); > } > } > > // […] > > array_map($$::getIdAbs(…, $idMap), $items); > > ``` > > I know this might be a little more exotic. But it is very straight forward > for static analysis tools. And no import has to be done for classes.
So right after I sent this, I just realised how significantly different it is all I just wrote. But actually using it with the array_map too I think. Because the closure created and the passed to the array_map has no relation to the items in the array passed as a second parameter. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php