Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45460 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73136 invoked from network); 3 Sep 2009 10:12:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2009 10:12:11 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.158 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 72.14.220.158 fg-out-1718.google.com Received: from [72.14.220.158] ([72.14.220.158:1573] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/53-56188-8769F9A4 for ; Thu, 03 Sep 2009 06:12:09 -0400 Received: by fg-out-1718.google.com with SMTP id d23so671467fga.11 for ; Thu, 03 Sep 2009 03:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=E4idvMyq+2iNPMc0eunBLVuzjRBNNK5xGPeDM+sL4ZM=; b=fm9oKCqgx/YDYZyI2sWDtXrJVDxKSVWwpObsdGoiIZ4+ywMqOdeuvF7V+LcOWfJch7 j50V3n2C5DwSezGel9k8UyDJ5rA4OVYU9wdp9pQhcpQ1mCYRb37LfoMMx8pat2u8Kt+e Uxe2RqE4C24OeeGTrcC56LQX+gcNrnh6ceV08= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Om3NJYnu9ZJsMlUsLb3Rfd545mZ7dEQLvg9cSJ34qic8wyUUZTQve4LvHyKtnJF9d8 rpvkcf0h3oHmh8VWs88XnZgsTCN3kdqZHYki4bDPR+hhgscSX2kPEdyBUz84hQW3yc1S x0J6flTCksrimEE4UIErU47SsRid7aJlECWPc= MIME-Version: 1.0 Received: by 10.86.13.37 with SMTP id 37mr3706005fgm.58.1251972726074; Thu, 03 Sep 2009 03:12:06 -0700 (PDT) In-Reply-To: References: Date: Thu, 3 Sep 2009 12:12:06 +0200 Message-ID: To: Sebastian Bergmann Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] ReflectionMethod::setAccessible() From: pierre.php@gmail.com (Pierre Joye) hi Sebastian, I like the idea, a definitive +1. I did not check the implementation yet however I'd to say that I'm not in favor of including it in 5.3.1 (for obvious reasons). Cheers, On Wed, Sep 2, 2009 at 9:48 PM, Sebastian Bergmann wrote: > =A0The patch below adds the ReflectionMethod::setAccessible() method and > =A0adds support for the ignore_visibility flag that is controlled by this > =A0method to ReflectionMethod::invoke() and ReflectionMethod::invokeArgs(= ). > > =A0The patch complements ReflectionProperty::setAccessible() that was add= ed > =A0in PHP 5.3.0. It has been developed for PHP_5_3 and I am proposing it > =A0for PHP 5.3.1 (it's a new feature, but a minor one). > > =A0If accepted, I will provide a patch against trunk as well as tests > =A0and documentation. > > =A0Cheers! > Sebastian > > Index: ext/reflection/php_reflection.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- ext/reflection/php_reflection.c =A0 =A0 (revision 287971) > +++ ext/reflection/php_reflection.c =A0 =A0 (working copy) > @@ -176,7 +176,6 @@ > =A0typedef struct _property_reference { > =A0 =A0 =A0 =A0zend_class_entry *ce; > =A0 =A0 =A0 =A0zend_property_info prop; > - =A0 =A0 =A0 unsigned int ignore_visibility:1; > =A0} property_reference; > > =A0/* Struct for parameters */ > @@ -201,6 +200,7 @@ > =A0 =A0 =A0 =A0reflection_type_t ref_type; > =A0 =A0 =A0 =A0zval *obj; > =A0 =A0 =A0 =A0zend_class_entry *ce; > + =A0 =A0 =A0 unsigned int ignore_visibility:1; > =A0} reflection_object; > > =A0static zend_object_handlers reflection_object_handlers; > @@ -1290,10 +1290,10 @@ > =A0 =A0 =A0 =A0reference =3D (property_reference*) emalloc(sizeof(propert= y_reference)); > =A0 =A0 =A0 =A0reference->ce =3D ce; > =A0 =A0 =A0 =A0reference->prop =3D *prop; > - =A0 =A0 =A0 reference->ignore_visibility =3D 0; > =A0 =A0 =A0 =A0intern->ptr =3D reference; > =A0 =A0 =A0 =A0intern->ref_type =3D REF_TYPE_PROPERTY; > =A0 =A0 =A0 =A0intern->ce =3D ce; > + =A0 =A0 =A0 intern->ignore_visibility =3D 0; > =A0 =A0 =A0 =A0zend_hash_update(Z_OBJPROP_P(object), "name", sizeof("name= "), (void **) &name, sizeof(zval *), NULL); > =A0 =A0 =A0 =A0zend_hash_update(Z_OBJPROP_P(object), "class", sizeof("cla= ss"), (void **) &classname, sizeof(zval *), NULL); > =A0} > @@ -2561,8 +2561,9 @@ > > =A0 =A0 =A0 =A0GET_REFLECTION_OBJECT_PTR(mptr); > > - =A0 =A0 =A0 if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 || (mptr->common.fn_flags & ZEND_ACC_ABSTRA= CT)) > + =A0 =A0 =A0 if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| (mptr->common.fn_flags & ZEND_ACC_ABS= TRACT)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& intern->ignore_visibility =3D=3D 0) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (mptr->common.fn_flags & ZEND_ACC_ABSTR= ACT) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0zend_throw_exception_ex(re= flection_exception_ptr, 0 TSRMLS_CC, > @@ -2669,8 +2670,9 @@ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return; > =A0 =A0 =A0 =A0} > > - =A0 =A0 =A0 if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 || (mptr->common.fn_flags & ZEND_ACC_ABSTRA= CT)) > + =A0 =A0 =A0 if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| (mptr->common.fn_flags & ZEND_ACC_ABS= TRACT)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& intern->ignore_visibility =3D=3D 0) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (mptr->common.fn_flags & ZEND_ACC_ABSTR= ACT) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0zend_throw_exception_ex(re= flection_exception_ptr, 0 TSRMLS_CC, > @@ -2959,6 +2961,28 @@ > =A0} > =A0/* }}} */ > > +/* {{{ proto public void ReflectionMethod::setAccessible() > + =A0 Sets whether non-public methods can be invoked */ > +ZEND_METHOD(reflection_method, setAccessible) > +{ > + =A0 =A0 =A0 reflection_object *intern; > + =A0 =A0 =A0 zend_bool visible; > + > + =A0 =A0 =A0 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &= visible) =3D=3D FAILURE) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 intern =3D getThis(); > + =A0 =A0 =A0 intern =3D (reflection_object *) zend_object_store_get_obje= ct(intern TSRMLS_CC); > + > + =A0 =A0 =A0 if (intern =3D=3D NULL) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 intern->ignore_visibility =3D visible; > +} > +/* }}} */ > + > =A0/* {{{ proto public static mixed ReflectionClass::export(mixed argumen= t [, bool return]) throws ReflectionException > =A0 =A0Exports a reflection object. Returns the output if TRUE is specifi= ed for return, printing it otherwise. */ > =A0ZEND_METHOD(reflection_class, export) > @@ -4375,10 +4399,10 @@ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0reference->prop =3D *property_info; > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0reference->ce =3D ce; > - =A0 =A0 =A0 reference->ignore_visibility =3D 0; > =A0 =A0 =A0 =A0intern->ptr =3D reference; > =A0 =A0 =A0 =A0intern->ref_type =3D REF_TYPE_PROPERTY; > =A0 =A0 =A0 =A0intern->ce =3D ce; > + =A0 =A0 =A0 intern->ignore_visibility =3D 0; > =A0} > =A0/* }}} */ > > @@ -4491,7 +4515,7 @@ > =A0 =A0 =A0 =A0METHOD_NOTSTATIC(reflection_property_ptr); > =A0 =A0 =A0 =A0GET_REFLECTION_OBJECT_PTR(ref); > > - =A0 =A0 =A0 if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICI= T_PUBLIC)) && ref->ignore_visibility =3D=3D 0) { > + =A0 =A0 =A0 if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICI= T_PUBLIC)) && intern->ignore_visibility =3D=3D 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_default_get_entry(getThis(), "name", size= of("name"), &name TSRMLS_CC); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0zend_throw_exception_ex(reflection_excepti= on_ptr, 0 TSRMLS_CC, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Cannot access non-public = member %s::%s", intern->ce->name, Z_STRVAL(name)); > @@ -4543,7 +4567,7 @@ > =A0 =A0 =A0 =A0METHOD_NOTSTATIC(reflection_property_ptr); > =A0 =A0 =A0 =A0GET_REFLECTION_OBJECT_PTR(ref); > > - =A0 =A0 =A0 if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && ref->ignore_vis= ibility =3D=3D 0) { > + =A0 =A0 =A0 if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_= visibility =3D=3D 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_default_get_entry(getThis(), "name", size= of("name"), &name TSRMLS_CC); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0zend_throw_exception_ex(reflection_excepti= on_ptr, 0 TSRMLS_CC, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Cannot access non-public = member %s::%s", intern->ce->name, Z_STRVAL(name)); > @@ -4660,14 +4684,20 @@ > =A0ZEND_METHOD(reflection_property, setAccessible) > =A0{ > =A0 =A0 =A0 =A0reflection_object *intern; > - =A0 =A0 =A0 property_reference *ref; > =A0 =A0 =A0 =A0zend_bool visible; > > =A0 =A0 =A0 =A0if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", = &visible) =3D=3D FAILURE) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return; > =A0 =A0 =A0 =A0} > - =A0 =A0 =A0 GET_REFLECTION_OBJECT_PTR(ref); > - =A0 =A0 =A0 ref->ignore_visibility =3D visible; > + > + =A0 =A0 =A0 intern =3D getThis(); > + =A0 =A0 =A0 intern =3D (reflection_object *) zend_object_store_get_obje= ct(intern TSRMLS_CC); > + > + =A0 =A0 =A0 if (intern =3D=3D NULL) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 intern->ignore_visibility =3D visible; > =A0} > =A0/* }}} */ > > @@ -5095,6 +5125,10 @@ > =A0 =A0 =A0 =A0ZEND_ARG_ARRAY_INFO(0, args, 0) > =A0ZEND_END_ARG_INFO() > > +ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_setAccessible, 0) > + =A0 =A0 =A0 ZEND_ARG_INFO(0, value) > +ZEND_END_ARG_INFO() > + > =A0static const zend_function_entry reflection_method_functions[] =3D { > =A0 =A0 =A0 =A0ZEND_ME(reflection_method, export, arginfo_reflection_meth= od_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) > =A0 =A0 =A0 =A0ZEND_ME(reflection_method, __construct, arginfo_reflection= _method___construct, 0) > @@ -5112,6 +5146,7 @@ > =A0 =A0 =A0 =A0ZEND_ME(reflection_method, invokeArgs, arginfo_reflection_= method_invokeArgs, 0) > =A0 =A0 =A0 =A0ZEND_ME(reflection_method, getDeclaringClass, NULL, 0) > =A0 =A0 =A0 =A0ZEND_ME(reflection_method, getPrototype, NULL, 0) > + =A0 =A0 =A0 ZEND_ME(reflection_property, setAccessible, arginfo_reflect= ion_method_setAccessible, 0) > =A0 =A0 =A0 =A0{NULL, NULL, NULL} > =A0}; > > > -- > Sebastian Bergmann =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Co-Founder and = Principal Consultant > http://sebastian-bergmann.de/ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 http://thePHP.cc/ > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Pierre http://blog.thepimp.net | http://www.libgd.org