Re: Introducing "Array Of" RFC

From: Date: Mon, 20 Jan 2014 22:00:18 +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  Groups: php.internals 
Request: Send a blank email to internals+get-71362@lists.php.net to get a copy of this message
Hi! > private $spanners = []; > public function __offsetset($key, $value) { if (!($value instanceof > Spanner)) throw new Exception("F-off"); $this->spanners[] = $value; } Right! So I don't see anything wrong with that. I'd be even OK with: public function __offsetset($key, Spanner $value) { $this->spanners[$key] = $value; } And that IMO covers 90% of use cases for Spanners[]. But, thinking more about it, if I *had* to choose between the two with no other options, I'd probably be happier with ArrayOf<Spanner> (provided that actually means just a generated class ArrayOf$Spanner and not checking every element of the actual array). Though IMO even this case if handled by one line of code, but at least here I can see *some* use case (namely, code generation if you have thousands of ArrayOf things and you *really* need to typecheck each and every one of them). Whether we need it or not is a bit of broader discussion - which I am leaning to "not" but we could argue about it. But at least it feels for me more "natural" - you just generate a bunch of code (there are a number of cans on worms in it but I ignore it for now). Checking each element post-factum just feels wrong way to approach it. It's like taking you car to a mechanic each time you'd like to drive somewhere (yes, car analogy, I live in America, what do you expect?) -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

« previous php.internals (#71362) next »