3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $scan = "00:12:a9:54:f6:a7,Privacy,-52.00,3Com,6,30:91:8f:24:07:d0,RSN: Privacy,-85.00,CenturyLink3873,1,00:0c:e5:46:2d:74,ShortSlotTime,-92.00,WLAN,1,c0:3f:0e:57:87:e8,RSN: Privacy,-94.00,Megan-PC-Wireless,6,00:12:a9:54:f6:a7,ShortPreamble,-45.00,WLAN,7"; $escan = (explode(",",$scan)); class Util { function arrayToObject() { //create an instance of an class without calling class's constructor $object = unserialize( sprintf( 'O:%d:"%s":0:{}', strlen($class), $class ) ); if (is_array($array)) { foreach ($array as $name => $value) { if (!empty($name)) { if(method_exists($object, 'set'.$name)){ $object->{'set'.$name}(Util::arrayToObject($value)); }else{ if(($strict)){ if(property_exists($class, $name)){ $object->$name = Util::arrayToObject($value); } }else{ $object->$name = Util::arrayToObject($value); } } } } return $object; } else { return FALSE; } } } $device = Util::arrayToObject($escan); var_dump($device); ?>
based on QJEPe
Output for 7.0.0 - 7.2.0
Deprecated: Non-static method Util::arrayToObject() should not be called statically in /in/67nfW on line 38 Notice: Undefined variable: class in /in/67nfW on line 12 Notice: Undefined variable: class in /in/67nfW on line 12 Notice: unserialize(): Error at offset 2 of 11 bytes in /in/67nfW on line 12 Notice: Undefined variable: array in /in/67nfW on line 15 bool(false)
Output for 5.3.17 - 5.6.28
Strict Standards: Non-static method Util::arrayToObject() should not be called statically in /in/67nfW on line 38 Notice: Undefined variable: class in /in/67nfW on line 12 Notice: Undefined variable: class in /in/67nfW on line 13 Notice: unserialize(): Error at offset 2 of 11 bytes in /in/67nfW on line 14 Notice: Undefined variable: array in /in/67nfW on line 15 bool(false)