static function getGlobalConstructor() { $Buffer = new Func('Buffer', function () { $self = new Buffer(); $self->init(func_get_args()); return $self; }); $Buffer->set('prototype', Buffer::$protoObject); $Buffer->setMethods(Buffer::$classMethods, true, false, true); return $Buffer; } } Buffer::$classMethods = array('isBuffer' => function ($obj) { global $Buffer; return _instanceof($obj, $Buffer); }, 'byteLength' => function ($string, $enc = null) { $b = new Buffer($string, $enc); return $b->length; }); Buffer::$protoMethods = array('get' => function ($index) { $self = Func::getContext(); $i = (int) $index; if ($i < 0 || $i >= $self->length) { throw new Ex(Error::create('offset is out of bounds')); } return (double) ord($self->raw[$i]); }, 'set' => function ($index, $byte) { $self = Func::getContext(); $i = (int) $index; if ($i < 0 || $i >= $self->length) { throw new Ex(Error::create('offset is out of bounds'));