Dear internals,
I would like to submit an RFC for supporting typed arrays as function/method argument and return types. Please either throw stones at me or give me enough karma to post it.
My php.net http://php.net/ username is tim-bezhashvyly.
Regards,
Tim
Tim Bezhashvyly wrote:
I would like to submit an RFC for supporting typed arrays as function/method argument and return types. Please either throw stones at me or give me enough karma to post it.
My php.net http://php.net/ username is tim-bezhashvyly.
Note that there is already https://wiki.php.net/rfc/arrayof, which has
been declined.
--
Christoph M. Becker
Tim Bezhashvyly wrote:
Please either throw stones at me or give me enough karma to post it.
Sorry, I have neither the ability to give karma, nor a convenient pile
of stones.
Christoph Becker wrote:
Note that there is already https://wiki.php.net/rfc/arrayof, which has
been declined.
The previous RFC was declined at least in part because of technical
aspects of the implementation. In particular, because the 'typed
array' wasn't implemented as a 'container'; instead the contents of
the array would need to be checked each time it was passed from one
function to another.
i.e. for the functions:
function fn1(Foo[] $fooArray) {
fn2($fooArray);
}
function fn2(Foo[] $fooArray) {
...
}
When fn1() calls fn2(), even though the PHP engine could know that
$fooArray contains only Foo elements, because of the way it was
implemented, the whole array would be iterated through by the engine,
comparing each entry to make sure that it is of type Foo.
A new RFC would probably need to address at least that issue. It might
also need to address a more general need for generics, rather than
just the specific case of arrays with a single type.
An alternative approach might be to introduce an RFC to make
ArrayObject be usable wherever an array is required. Then people could
implement a simple container themselves:
class FooArray extends ArrayObject {
function offsetSet($index, $newval) {
if ($newval instanceof Foo) {
throw new TypeError("$newval is not a Foo");
}
parent::offsetSet($index, $newval);
}
}
cheers
Dan
Hi all,
I would like to submit an RFC for supporting typed arrays as
function/method argument and return types. Please either throw stones at me
or give me enough karma to post it.My php.net http://php.net/ username is tim-bezhashvyly.
Note that there is already https://wiki.php.net/rfc/arrayof, which has
been declined.
I would like to have something similar to JSON Schema Validation.
This could be a function unlike arrayof.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net