LoginSignup
1
1

More than 5 years have passed since last update.

組み込み関数の挙動をdeckorate拡張で置き換える

Posted at

deckorate拡張は
https://github.com/t3rmin4t0r/deckorate
から落とせます。phpizeして実行すると

<?php
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;

class User
{
    private $name = 'john';
    private $password;

    public function getName()
    {  
        return $this->name;
    }
}

if (deckorate("json_encode", '__json_encode')) {
    function json_encode($value, $options = 0) {
        if (is_object($value)) {
            $value = (new ClassMethodsHydrator)->extract($value);
        }

        return __json_encode($value, $options);
    }
}

var_dump(json_encode(new User)); // string(15) "{"name":"john"}"

http://www.php.net/manual/ja/function.runkit-function-redefine.php
に対する利点?? 小さいとか?

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1