Hi PHP-fellows
or whoever reads this…
I’m a Belgian PHP addict and feel I’ve got a suggestion that might be of
interest for PHP7.
I’d more than glad to write it down completely in an RFC if you grant me
access, otherwise, maybe someone can do it.
My username is dgoosens.
I feel, a natural evolution of the scalar type hinting would be the
possibility to type hint arrays as well…
That means, not the array itself, obviously, but the items that are in the
array.
Right now we have
array $foo = array();
What I’d like to see is something like this:
string[] $foo = array(); // an array that can only contain
stringsarray[string[]] $foo = array(); // an array that can only
contain arrays that contain stringsBar[] $foo = array(); // an array
that can only contain instances of Bar
There probably are some side effects to this and maybe I’m not aware enough
about PHP’s internals, but I think this implementation would have a series
of benefits…
1. function attributes type hinting
public function bar(string[] $foo = array()){
/* No need to validate the data in $foo as we already know that
it will only contain strings */}
2. class attributes
class foo
{
public $foo = string[];
}
$bar = new foo();$bar->foo[] = 'only strings are allowed here';
etc. etc.
I feel this would be a very nice improvement in PHP…
Thanks
dgoosens
Dmitri Goosens wrote:
I’m a Belgian PHP addict and feel I’ve got a suggestion that might be of
interest for PHP7.
I’d more than glad to write it down completely in an RFC if you grant me
access, otherwise, maybe someone can do it.
Information about creating an RFC can be found on
https://wiki.php.net/rfc/howto
My username is dgoosens.
If you already have registered with that name for a Wiki account, one of
the admins would have to approve it. Otherwise you'd have to register
yourself at first.
I feel, a natural evolution of the scalar type hinting would be the
possibility to type hint arrays as well…
That means, not the array itself, obviously, but the items that are in the
array.
Note that there has been a related RFC a while ago, which has been
declined: https://wiki.php.net/rfc/arrayof. It might be a good idea
to read the respective mailing list discussion:
http://grokbase.com/t/php/php-internals/141f1kzdm8/introducing-array-of-rfc
--
Christoph M. Becker
Thanks a lot Christoph
Vielen Dank !
Dmitri Goosens wrote:
I’m a Belgian PHP addict and feel I’ve got a suggestion that might be of
interest for PHP7.
I’d more than glad to write it down completely in an RFC if you grant me
access, otherwise, maybe someone can do it.Information about creating an RFC can be found on
https://wiki.php.net/rfc/howto
My username is dgoosens.
If you already have registered with that name for a Wiki account, one of
the admins would have to approve it. Otherwise you'd have to register
yourself at first.I feel, a natural evolution of the scalar type hinting would be the
possibility to type hint arrays as well…
That means, not the array itself, obviously, but the items that are in
the
array.Note that there has been a related RFC a while ago, which has been
declined: https://wiki.php.net/rfc/arrayof. It might be a good idea
to read the respective mailing list discussion:<
http://grokbase.com/t/php/php-internals/141f1kzdm8/introducing-array-of-rfc--
Christoph M. Becker