Re: Introducing "Array Of" RFC

From: Date: Mon, 20 Jan 2014 21:19:13 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  Groups: php.internals 
Request: Send a blank email to internals+get-71357@lists.php.net to get a copy of this message
> Note that neither generics nor array strict typing gives you that. > Neither of them can control what is being put into the bag. The only > thing you can do is to look in the bag and reject what has been put > there post-factum (actually, with generics you can't do even that - > generics parametrize you types, but you still have to have the > typechecks somewhere, so from type checking point generics change > nothing) - i.e. the check happens not when something is put in the bag > but when you get the bag and you have to examine that bag (every single > time you touch it) and pull out each element of it and ensure it is > still a spanner. If you put the bag down, next time you touch it you > have to pull out every single thing out of the bag and check if it is a > spanner *again*. Is it really the bag you want to deal with? I wouldn't > really want to own such bag, I'm not OCD enough for that :) > Well, arrayof using generics-like syntax doesn't give you entrance type checking, but actual generics would. Or, to map it into current PHP terms: private $spanners = []; public function __offsetset($key, $value) { if (!($value instanceof Spanner)) throw new Exception("F-off"); $this->spanners[] = $value; } But this RFC isn't about generics, it's about arrayof typehinting and ways to make that work for PHP. Your point about perf is absolutely valid and one which I'd still like to hear addressed. -Sara

« previous php.internals (#71357) next »