Re: Re: Bug 67072 resolution for 5.4/5.5
| From: | Remi Collet | Date: | Tue, 24 Jun 2014 11:42:52 +0000 |
| Subject: | Re: Re: Bug 67072 resolution for 5.4/5.5 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75060@lists.php.net to get a copy of this message | ||
Le 24/06/2014 09:58, Stas Malyshev a écrit :
> I understand that this creates a need that we do not cover of how to
> mock such objects, and I welcome suggestions - including how to make
> newInstanceArgWithoutConstructor safe. But currently I do not see how we
> can leave the unserialize hack in for classes like SplFileObject -
> unless somebody points me to a way to make it safe.
Proposal, hawfull hack attached.
Obviously, this doesn't make newInstanceWithoutConstructor safe ;)
But this answer the need.
And we can state in documentation.
"force : allow to instantiate internal classes. Never use this !"
And nobody could complain if this cause segfault.
Remi.
--- ext/reflection/php_reflection.c.orig 2014-06-24 13:23:11.265725787 +0200 +++ ext/reflection/php_reflection.c 2014-06-24 13:21:30.881302839 +0200 @@ -4295,11 +4295,16 @@ { reflection_object *intern; zend_class_entry *ce; + zend_bool force = 0; METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - if (ce->create_object != NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &force) == FAILURE) { + return; + } + + if (ce->create_object != NULL && !force) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name); }
--- ext/reflection/php_reflection.c.orig 2014-06-24 13:23:11.265725787 +0200 +++ ext/reflection/php_reflection.c 2014-06-24 13:21:30.881302839 +0200 @@ -4295,11 +4295,16 @@ { reflection_object *intern; zend_class_entry *ce; + zend_bool force = 0; METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - if (ce->create_object != NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &force) == FAILURE) { + return; + } + + if (ce->create_object != NULL && !force) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name); }