ID:               37450
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mega-squall at caramail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: ALL
 PHP Version:      5.1.4
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's impossible and never will be.

But you can do that more or less yourself.

Derive a class that implements ArrayAccess or reuse
ArrayObject/ArrayIterator. And overload its offsetSet(). In the method
body you add the check to ensure only what you want can go in.

Now if that class accepts only B's you may call it ArrayOfB and the use
ArrayOfB as you typehint.

So obviously  this is a question for [EMAIL PROTECTED]


Previous Comments:
------------------------------------------------------------------------

[2006-05-15 21:47:29] mega-squall at caramail dot com

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__



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37450&edit=1

Reply via email to