Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foo($t) {
- $result;
- foreach($t as $val) {
- $result = dosomething($result, $val);
- }
- return $result;
- }
- function foo(Traversable $t) {
- Argument 1 passed to foo() must implement interface Traversable, array given
- function foo(array $a) {}
- function bar(Traversable $a) {}
- function foobar($a) {}
- $array = array(1,2,3)
- $traversable = new MyTraversableObject();
- foo($array);
- foo(iterator_to_array($traversable));
- bar(new ArrayIterator($array));
- bar($traversable);
- foobar($array);
- foobar($traversable);
- function MyFunction($traversable)
- {
- if(!$traversable instanceof Traversable && !is_array($traversable))
- {
- throw new InvalidArgumentException(sprintf(
- 'Myfunction($traversable = %s): Invalid argument $traversable.'
- ,var_export($traversable, true)
- ));
- }
- }
- public function MyMethod($traversable)
- {
- if(!$traversable instanceof Traversable && !is_array($traversable))
- {
- throw new InvalidArgumentException(sprintf(
- '%s::MyMethod($traversable): Invalid argument $traversable of type `%s`.'
- ,get_class($this)
- ,gettype($traversable)
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement