- var_dump: documentation ( source)
- json_decode: documentation ( source)
- json_encode: documentation ( source)
<?php
class test {
public $chciDoArray1 = '1';
public $chciDoArray2 = '2';
public $chciDoArray3 = '3';
public $neChciDoArray = 'oops';
public function ohMyHandsWillFallOff()
{
return [
'chciDoArray1' => $this->chciDoArray1,
'chciDoArray2' => $this->chciDoArray2,
'chciDoArray3' => $this->chciDoArray3,
];
}
public function __toArray()
{
return [
'chciDoArray1' => $this->chciDoArray1,
'chciDoArray2' => $this->chciDoArray2,
'chciDoArray3' => $this->chciDoArray3,
];
}
}
$a = new test();
var_dump((array)$a, json_decode(json_encode($a), true), $a->ohMyHandsWillFallOff());