Have a strange problem with methods..

if i use function to return some array and doing 2-level nested foreach(),
for example
function x(){
 return array(1, 2,3);
}

foreach(x() as $key){
 echo $key ."<br>";
 foreach(x() as $key2){
  echo "&nbsp;&nbsp;" . $key2 . "<br>";
 }
}

everything works fine ... the output is
2
  2
  3
3
  2
  3


But when i do it with object method and property i behaves unwanted, and
breaks loop after first nested foreach() stops

class Foo{
 var $y;
 function Foo(){
  $this -> y = array(2,3);
 }

 function gety(){
  return $this -> y;
 }
}

$x = new Foo;

foreach($x->gety() as $key){
 echo $key ."<br>";
 foreach($x->gety() as $key2){
  echo "&nbsp;&nbsp;" . $key2 . "<br>";
 }
}

it returns

2
  2
  3

Can anybody explain what is it ? a normal behavior or bug ?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to