[wp-hackers] PHP Coding Practices

Robert Deaton false.hopes at gmail.com
Wed Feb 15 06:34:17 GMT 2006


On 2/15/06, Dave Grijalva <grijalva at gmail.com> wrote:
> actually, it is in php4:
>
> :~ dave$ php4
> <?php
> class test {
> var $a;
> var $b;
> }
>
> $test = new test();
> $test->a = 'abc';
> $test->b = 'hey, you';
>
> foreach($test as $key => $val){
>  echo "$key: $val";
> echo "\n";
> }
> ?>
> ------  output ------
> a: abc
> b: hey, you
>
> it may not be documented, but it's there.

Actually, that's a typecast. Try using an explicit one in the code,
you'll notice that it runs the same.

lappy ~ # php
<?php
class test {
var $a;
var $b;
}

$test = new test();
$test->a = 'abc';
$test->b = 'hey, you';

var_dump((array) $test);
?>

array(2) {
  ["a"]=>
  string(3) "abc"
  ["b"]=>
  string(8) "hey, you"
}

Mark, you were right, and the documentation is correct.

--
--Robert Deaton
http://somethingunpredictable.com


More information about the wp-hackers mailing list