* Creates the global constructor used in user-land * @return Func */ static function getGlobalConstructor() { $RegExp = new Func(function () { $reg = new RegExp(); $reg->init(func_get_args()); return $reg; }); $RegExp->set('prototype', RegExp::$protoObject); $RegExp->setMethods(RegExp::$classMethods, true, false, true); return $RegExp; } } RegExp::$classMethods = array(); RegExp::$protoMethods = array('exec' => function ($str) { $self = Func::getContext(); $str = to_string($str); //todo $offset $offset = 0; $result = preg_match($self->toString(true), $str, $matches, PREG_OFFSET_CAPTURE, $offset); if ($result === false) { throw new Ex(Error::create('Error executing Regular Expression: ' . $self->toString())); } if ($result === 0) { return Object::$null; } $index = $matches[0][1]; $self->set('lastIndex', (double) ($index + strlen($matches[0][0]))); $arr = new Arr();