forcing access to __PHP_Incomplete_Class object properties

前端 未结 8 1900
夕颜
夕颜 2020-11-30 06:43

I\'m writing a module for a php cms. In a function (a callback) I can access an object that comes from the framework code.

This object is of type __PHP_Incomp

8条回答
  •  醉酒成梦
    2020-11-30 07:12

    I found this hack which will let you cast an object:

    function casttoclass($class, $object)
    {
      return unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', serialize($object)));
    }
    

    From http://blog.adaniels.nl/articles/a-dark-corner-of-php-class-casting/

    So you can do:

    $obj = casttoclass('stdClass', $incompleteObject);
    

    and then access properties as normal.


    You could also define an unserialize_callback_func in a .htaccess/Apache configuration file. That way you wouldn't need to hack any PHP but you could include the file on demand.

提交回复
热议问题