From c6d10ce255472d9f141d77b48bddaea152f9ea64 Mon Sep 17 00:00:00 2001 From: seanc Date: Fri, 29 Mar 2013 16:47:38 -0700 Subject: [PATCH] Add HPHP support for newInstanceWithoutConstructor Add support for PHP >=5.4 ReflectionClass::newInstanceWithoutConstructor --- hphp/idl/reflection.idl.php | 17 +++++++++++++++++ hphp/runtime/ext/ext_reflection.cpp | 4 ++++ hphp/runtime/ext/ext_reflection.h | 1 + hphp/system/classes/reflection.php | 13 +++++++++++++ hphp/system/reflection.inc | 1 + hphp/test/vm/reflection_noconstuctor.php | 13 +++++++++++++ hphp/test/vm/reflection_noconstuctor.php.exp | 3 +++ 7 files changed, 52 insertions(+) create mode 100644 hphp/test/vm/reflection_noconstuctor.php create mode 100644 hphp/test/vm/reflection_noconstuctor.php.exp diff --git a/hphp/idl/reflection.idl.php b/hphp/idl/reflection.idl.php index 95357228e..b820f408b 100644 --- a/hphp/idl/reflection.idl.php +++ b/hphp/idl/reflection.idl.php @@ -251,6 +251,23 @@ DefineFunction( 'taint_observer' => false, )); +DefineFunction( + array( + 'name' => "hphp_create_object_without_constructor", + 'desc' => "Used by FFI interface for other languages to call into PHP.", + 'flags' => HasDocComment | HipHopSpecific | NoInjection, + 'return' => array( + 'type' => Object, + ), + 'args' => array( + array( + 'name' => "name", + 'type' => String, + ), + ), + 'taint_observer' => false, + )); + DefineFunction( array( 'name' => "hphp_get_property", diff --git a/hphp/runtime/ext/ext_reflection.cpp b/hphp/runtime/ext/ext_reflection.cpp index 08a10d1a8..45e883faa 100644 --- a/hphp/runtime/ext/ext_reflection.cpp +++ b/hphp/runtime/ext/ext_reflection.cpp @@ -862,6 +862,10 @@ Object f_hphp_create_object(CStrRef name, CArrRef params) { return g_vmContext->createObject(name.get(), params); } +Object f_hphp_create_object_without_constructor(CStrRef name) { + return g_vmContext->createObject(name.get(), nullptr, false); +} + Variant f_hphp_get_property(CObjRef obj, CStrRef cls, CStrRef prop) { return obj->o_get(prop); } diff --git a/hphp/runtime/ext/ext_reflection.h b/hphp/runtime/ext/ext_reflection.h index 18c658c01..52c5254c7 100644 --- a/hphp/runtime/ext/ext_reflection.h +++ b/hphp/runtime/ext/ext_reflection.h @@ -35,6 +35,7 @@ Variant f_hphp_invoke(CStrRef name, CArrRef params); Variant f_hphp_invoke_method(CVarRef obj, CStrRef cls, CStrRef name, CArrRef params); bool f_hphp_instanceof(CObjRef obj, CStrRef name); Object f_hphp_create_object(CStrRef name, CArrRef params); +Object f_hphp_create_object_without_constructor(CStrRef name); Variant f_hphp_get_property(CObjRef obj, CStrRef cls, CStrRef prop); void f_hphp_set_property(CObjRef obj, CStrRef cls, CStrRef prop, CVarRef value); Variant f_hphp_get_static_property(CStrRef cls, CStrRef prop); diff --git a/hphp/system/classes/reflection.php b/hphp/system/classes/reflection.php index b63ba05c4..c2c35cb8f 100644 --- a/hphp/system/classes/reflection.php +++ b/hphp/system/classes/reflection.php @@ -1257,6 +1257,19 @@ class ReflectionClass implements Reflector { return hphp_create_object($this->name, array_values($args)); } +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from + * http://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php ) + * + * Creates a new instance of the class without invoking the constructor. + * + * @return mixed Returns a new instance of the class. + */ + public function newInstanceWithoutConstructor() { + return hphp_create_object_without_constructor($this->name); + } + // Do NOT modifiy this doc comment block generated by idl/sysdoc.php /** * ( excerpt from diff --git a/hphp/system/reflection.inc b/hphp/system/reflection.inc index 20a386f75..6f0f11814 100644 --- a/hphp/system/reflection.inc +++ b/hphp/system/reflection.inc @@ -11,6 +11,7 @@ "hphp_invoke_method", T(Variant), S(0), "obj", T(Variant), NULL, S(0), NULL, S(0), "cls", T(String), NULL, S(0), NULL, S(0), "name", T(String), NULL, S(0), NULL, S(0), "params", T(Array), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @obj mixed\n * @cls string\n * @name string\n * @params vector\n *\n * @return mixed\n */", "hphp_instanceof", T(Boolean), S(0), "obj", T(Object), NULL, S(0), NULL, S(0), "name", T(String), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @obj object\n * @name string\n *\n * @return bool\n */", "hphp_create_object", T(Object), S(0), "name", T(String), NULL, S(0), NULL, S(0), "params", T(Array), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @name string\n * @params vector\n *\n * @return object\n */", +"hphp_create_object_without_constructor", T(Object), S(0), "name", T(String), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @name string\n *\n * @return object\n */", "hphp_get_property", T(Variant), S(0), "obj", T(Object), NULL, S(0), NULL, S(0), "cls", T(String), NULL, S(0), NULL, S(0), "prop", T(String), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @obj object\n * @cls string\n * @prop string\n *\n * @return mixed\n */", "hphp_set_property", T(Void), S(0), "obj", T(Object), NULL, S(0), NULL, S(0), "cls", T(String), NULL, S(0), NULL, S(0), "prop", T(String), NULL, S(0), NULL, S(0), "value", T(Variant), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @obj object\n * @cls string\n * @prop string\n * @value mixed\n */", "hphp_get_static_property", T(Variant), S(0), "cls", T(String), NULL, S(0), NULL, S(0), "prop", T(String), NULL, S(0), NULL, S(0), NULL, S(4276224), "/**\n * ( HipHop specific )\n *\n * Used by FFI interface for other languages to call into PHP.\n *\n * @cls string\n * @prop string\n *\n * @return mixed\n */", diff --git a/hphp/test/vm/reflection_noconstuctor.php b/hphp/test/vm/reflection_noconstuctor.php new file mode 100644 index 000000000..a92ffd75a --- /dev/null +++ b/hphp/test/vm/reflection_noconstuctor.php @@ -0,0 +1,13 @@ +newInstance(); +$c3 = (new ReflectionClass('foo'))->newInstanceArgs(array()); +$no_c = (new ReflectionClass('foo'))->newInstanceWithoutConstructor(); diff --git a/hphp/test/vm/reflection_noconstuctor.php.exp b/hphp/test/vm/reflection_noconstuctor.php.exp new file mode 100644 index 000000000..811e6b836 --- /dev/null +++ b/hphp/test/vm/reflection_noconstuctor.php.exp @@ -0,0 +1,3 @@ +this should only be printed three times! +this should only be printed three times! +this should only be printed three times!