Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45449 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56504 invoked from network); 2 Sep 2009 20:08:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2009 20:08:40 -0000 Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.177 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-vw0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:50544] helo=mail-vw0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2B/00-56016-5C0DE9A4 for ; Wed, 02 Sep 2009 16:08:38 -0400 Received: by vws7 with SMTP id 7so1037122vws.29 for ; Wed, 02 Sep 2009 13:08:35 -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=+bF+nShABxd4MkpSgBX+UC91jCuOiW2XVikbR03F0DA=; b=wsXsRREQYPiPLF4ArgfLBumj/uo+DLrPZLcHmLIfqu3XizpFW5Gm7586etGg3XcriC Eb3T6TGOZA8HVuEyDRNsO04PI/9GTkYe0xeplyTqdU2aCif8J6a5AMh/fG/rSM7fwW6Q pEKEkYK3gkwCz6vyNjNznmEwqH0uvs+wZXb1o= 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=wZhq3E/S3SZ7O9Rwd29SrTIxQnBw+qpKxLvXxHU9vLJ9y9g6eWeSqr1+RW/Lw59335 058Pngj13DZUUz4zWHqLmccpZDvdqUfEw+TREqZqzi6PC+M7UEduY+2ciw6crqVBYdqB 6oveH8H/vXn2WwHfieSNYs0h+/Gy1m4MnSvL4= MIME-Version: 1.0 Received: by 10.220.79.168 with SMTP id p40mr11667723vck.110.1251922115334; Wed, 02 Sep 2009 13:08:35 -0700 (PDT) In-Reply-To: References: Date: Wed, 2 Sep 2009 17:08:35 -0300 Message-ID: To: Sebastian Bergmann Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] ReflectionMethod::setAccessible() From: guilhermeblanco@gmail.com (Guilherme Blanco) This is a BC break and may possibly be rejected. Extended classes may implement a method with same name. Point is that Reflection API misses it and it should be added even prior to 5.3.0 be released. Currently there's no way to achieve such behavior. So I'm +1. Cheers, On Wed, Sep 2, 2009 at 4:48 PM, Sebastian Bergmann wrote: > =C2=A0The patch below adds the ReflectionMethod::setAccessible() method a= nd > =C2=A0adds support for the ignore_visibility flag that is controlled by t= his > =C2=A0method to ReflectionMethod::invoke() and ReflectionMethod::invokeAr= gs(). > > =C2=A0The patch complements ReflectionProperty::setAccessible() that was = added > =C2=A0in PHP 5.3.0. It has been developed for PHP_5_3 and I am proposing = it > =C2=A0for PHP 5.3.1 (it's a new feature, but a minor one). > > =C2=A0If accepted, I will provide a patch against trunk as well as tests > =C2=A0and documentation. > > =C2=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 =C2=A0 =C2=A0 (revision 287971) > +++ ext/reflection/php_reflection.c =C2=A0 =C2=A0 (working copy) > @@ -176,7 +176,6 @@ > =C2=A0typedef struct _property_reference { > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_class_entry *ce; > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_property_info prop; > - =C2=A0 =C2=A0 =C2=A0 unsigned int ignore_visibility:1; > =C2=A0} property_reference; > > =C2=A0/* Struct for parameters */ > @@ -201,6 +200,7 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0reflection_type_t ref_type; > =C2=A0 =C2=A0 =C2=A0 =C2=A0zval *obj; > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_class_entry *ce; > + =C2=A0 =C2=A0 =C2=A0 unsigned int ignore_visibility:1; > =C2=A0} reflection_object; > > =C2=A0static zend_object_handlers reflection_object_handlers; > @@ -1290,10 +1290,10 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0reference =3D (property_reference*) emalloc(si= zeof(property_reference)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0reference->ce =3D ce; > =C2=A0 =C2=A0 =C2=A0 =C2=A0reference->prop =3D *prop; > - =C2=A0 =C2=A0 =C2=A0 reference->ignore_visibility =3D 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ptr =3D reference; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ref_type =3D REF_TYPE_PROPERTY; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ce =3D ce; > + =C2=A0 =C2=A0 =C2=A0 intern->ignore_visibility =3D 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_hash_update(Z_OBJPROP_P(object), "name", = sizeof("name"), (void **) &name, sizeof(zval *), NULL); > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_hash_update(Z_OBJPROP_P(object), "class",= sizeof("class"), (void **) &classname, sizeof(zval *), NULL); > =C2=A0} > @@ -2561,8 +2561,9 @@ > > =C2=A0 =C2=A0 =C2=A0 =C2=A0GET_REFLECTION_OBJECT_PTR(mptr); > > - =C2=A0 =C2=A0 =C2=A0 if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 || (mptr->common.fn_fl= ags & ZEND_ACC_ABSTRACT)) > + =C2=A0 =C2=A0 =C2=A0 if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|| (mptr->common= .fn_flags & ZEND_ACC_ABSTRACT)) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&& intern->ignor= e_visibility =3D=3D 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (mptr->common.f= n_flags & ZEND_ACC_ABSTRACT) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, > @@ -2669,8 +2670,9 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > > - =C2=A0 =C2=A0 =C2=A0 if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 || (mptr->common.fn_fl= ags & ZEND_ACC_ABSTRACT)) > + =C2=A0 =C2=A0 =C2=A0 if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|| (mptr->common= .fn_flags & ZEND_ACC_ABSTRACT)) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&& intern->ignor= e_visibility =3D=3D 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (mptr->common.f= n_flags & ZEND_ACC_ABSTRACT) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, > @@ -2959,6 +2961,28 @@ > =C2=A0} > =C2=A0/* }}} */ > > +/* {{{ proto public void ReflectionMethod::setAccessible() > + =C2=A0 Sets whether non-public methods can be invoked */ > +ZEND_METHOD(reflection_method, setAccessible) > +{ > + =C2=A0 =C2=A0 =C2=A0 reflection_object *intern; > + =C2=A0 =C2=A0 =C2=A0 zend_bool visible; > + > + =C2=A0 =C2=A0 =C2=A0 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_C= C, "b", &visible) =3D=3D FAILURE) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 intern =3D getThis(); > + =C2=A0 =C2=A0 =C2=A0 intern =3D (reflection_object *) zend_object_store= _get_object(intern TSRMLS_CC); > + > + =C2=A0 =C2=A0 =C2=A0 if (intern =3D=3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 intern->ignore_visibility =3D visible; > +} > +/* }}} */ > + > =C2=A0/* {{{ proto public static mixed ReflectionClass::export(mixed argu= ment [, bool return]) throws ReflectionException > =C2=A0 =C2=A0Exports a reflection object. Returns the output if TRUE is s= pecified for return, printing it otherwise. */ > =C2=A0ZEND_METHOD(reflection_class, export) > @@ -4375,10 +4399,10 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0reference->prop = =3D *property_info; > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0reference->ce =3D ce; > - =C2=A0 =C2=A0 =C2=A0 reference->ignore_visibility =3D 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ptr =3D reference; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ref_type =3D REF_TYPE_PROPERTY; > =C2=A0 =C2=A0 =C2=A0 =C2=A0intern->ce =3D ce; > + =C2=A0 =C2=A0 =C2=A0 intern->ignore_visibility =3D 0; > =C2=A0} > =C2=A0/* }}} */ > > @@ -4491,7 +4515,7 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0METHOD_NOTSTATIC(reflection_property_ptr); > =C2=A0 =C2=A0 =C2=A0 =C2=A0GET_REFLECTION_OBJECT_PTR(ref); > > - =C2=A0 =C2=A0 =C2=A0 if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_AC= C_IMPLICIT_PUBLIC)) && ref->ignore_visibility =3D=3D 0) { > + =C2=A0 =C2=A0 =C2=A0 if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_AC= C_IMPLICIT_PUBLIC)) && intern->ignore_visibility =3D=3D 0) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_default_get_entry= (getThis(), "name", sizeof("name"), &name TSRMLS_CC); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_throw_excepti= on_ex(reflection_exception_ptr, 0 TSRMLS_CC, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"Cannot access non-public member %s::%s", intern->ce->name, Z_STR= VAL(name)); > @@ -4543,7 +4567,7 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0METHOD_NOTSTATIC(reflection_property_ptr); > =C2=A0 =C2=A0 =C2=A0 =C2=A0GET_REFLECTION_OBJECT_PTR(ref); > > - =C2=A0 =C2=A0 =C2=A0 if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && ref->i= gnore_visibility =3D=3D 0) { > + =C2=A0 =C2=A0 =C2=A0 if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern= ->ignore_visibility =3D=3D 0) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_default_get_entry= (getThis(), "name", sizeof("name"), &name TSRMLS_CC); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_throw_excepti= on_ex(reflection_exception_ptr, 0 TSRMLS_CC, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"Cannot access non-public member %s::%s", intern->ce->name, Z_STR= VAL(name)); > @@ -4660,14 +4684,20 @@ > =C2=A0ZEND_METHOD(reflection_property, setAccessible) > =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0reflection_object *intern; > - =C2=A0 =C2=A0 =C2=A0 property_reference *ref; > =C2=A0 =C2=A0 =C2=A0 =C2=A0zend_bool visible; > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (zend_parse_parameters(ZEND_NUM_ARGS() TSRM= LS_CC, "b", &visible) =3D=3D FAILURE) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > - =C2=A0 =C2=A0 =C2=A0 GET_REFLECTION_OBJECT_PTR(ref); > - =C2=A0 =C2=A0 =C2=A0 ref->ignore_visibility =3D visible; > + > + =C2=A0 =C2=A0 =C2=A0 intern =3D getThis(); > + =C2=A0 =C2=A0 =C2=A0 intern =3D (reflection_object *) zend_object_store= _get_object(intern TSRMLS_CC); > + > + =C2=A0 =C2=A0 =C2=A0 if (intern =3D=3D NULL) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; > + =C2=A0 =C2=A0 =C2=A0 } > + > + =C2=A0 =C2=A0 =C2=A0 intern->ignore_visibility =3D visible; > =C2=A0} > =C2=A0/* }}} */ > > @@ -5095,6 +5125,10 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ARG_ARRAY_INFO(0, args, 0) > =C2=A0ZEND_END_ARG_INFO() > > +ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_setAccessible, 0) > + =C2=A0 =C2=A0 =C2=A0 ZEND_ARG_INFO(0, value) > +ZEND_END_ARG_INFO() > + > =C2=A0static const zend_function_entry reflection_method_functions[] =3D = { > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ME(reflection_method, export, arginfo_ref= lection_method_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ME(reflection_method, __construct, arginf= o_reflection_method___construct, 0) > @@ -5112,6 +5146,7 @@ > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ME(reflection_method, invokeArgs, arginfo= _reflection_method_invokeArgs, 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ME(reflection_method, getDeclaringClass, = NULL, 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0ZEND_ME(reflection_method, getPrototype, NULL,= 0) > + =C2=A0 =C2=A0 =C2=A0 ZEND_ME(reflection_property, setAccessible, arginf= o_reflection_method_setAccessible, 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0{NULL, NULL, NULL} > =C2=A0}; > > > -- > Sebastian Bergmann =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0Co-Founder and Principal Consultant > http://sebastian-bergmann.de/ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 http://thePHP.cc/ > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Guilherme Blanco - Web Developer CBC - Certified Bindows Consultant Cell Phone: +55 (16) 9215-8480 MSN: guilhermeblanco@hotmail.com URL: http://blog.bisna.com S=C3=A3o Paulo - SP/Brazil