|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-05-15 21:53 UTC] helly@php.net
[2006-05-15 21:55 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jan 07 23:00:01 2026 UTC |
Description: ------------ Type Hinting is compatible with array and objects, but not with array containing ONLY instances of single chosen class (array of instances). This would be appreciated, if relevant with the structure of arrays. Reproduce code: --------------- class B { public $field; public __construct ($param) { $this->field = $param; } } class A { public function method (B[] $parameters){ foreach ($parameters as $object) { echo $object->field . "\n"; } } } $b = Array (); for ($count=0; $count<10; $count++) { $b[] = new B ($count); } $a = new A (); $a->method ($b); Expected result: ---------------- 0 1 2 3 4 5 6 7 8 9 Actual result: -------------- Parse error: syntax error, unexpected '[', expecting '&' or T_VARIABLE in __FILE__ on line __LINE__