Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21173 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24099 invoked by uid 1010); 11 Dec 2005 12:39:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 24084 invoked from network); 11 Dec 2005 12:39:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2005 12:39:46 -0000 X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:34818] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 77/B7-49905-FED1C934 for ; Sun, 11 Dec 2005 07:39:11 -0500 Received: from [192.168.1.3] (dslb-084-063-004-249.pools.arcor-ip.net [84.63.4.249]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id 7E0B7610283; Sun, 11 Dec 2005 13:46:23 +0100 (CET) Date: Sun, 11 Dec 2005 13:36:40 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <254577468.20051211133640@marcus-boerger.de> To: Sebastian Bergmann Cc: internals@lists.php.net In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] bad type specifier while parsing parameters From: helly@php.net (Marcus Boerger) Hello Sebastian, fixed in cvs - and btw it took me 5 seconds to fix - i bet you could have done it yourself :-) best regards marcus Sunday, December 11, 2005, 1:25:26 PM, you wrote: > The code below (which is based on Derick's code [1]) used to work until > recently: > class ClassWithNonPublicProperties { > protected $protectedProperty = 'foo'; > private $privateProperty = 'bar'; > } > function getNonPublicProperty($object, $propertyName) { > try { > $class = new ReflectionClass($object); > if ($class->hasProperty($propertyName)) { > $property = $class->getProperty($propertyName); > if (!$property->isPublic()) { > if ($property->isProtected()) { > $propertyName = "\0*\0" . $propertyName; > } else { > $propertyName = sprintf( > "\0%s\0%s", > get_class($object), > $propertyName > ); > } > $tmp = (array) $object; > return $tmp[$propertyName]; > } else { > return $object->$propertyName; > } > } else { > throw new InvalidArgumentException; > } > } > catch (ReflectionException $e) { > throw new InvalidArgumentException; > } > } > $object = new ClassWithNonPublicProperties; > print getNonPublicProperty($object, 'protectedProperty') . "\n"; > print getNonPublicProperty($object, 'privateProperty') . "\n"; > ?> > The current PHP_5_1 prints > Warning: ReflectionClass::getProperty(): > bad type specifier while parsing parameters in test.php on line 12 > Fatal error: Call to a member function isPublic() on a non-object > in test.php on line 14 > Is this change in behaviour intentional or should I file a bug report > for this? > -- > [1] http://derickrethans.nl/private_properties_exposed.php > -- > Sebastian Bergmann http://www.sebastian-bergmann.de/ > GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69 Best regards, Marcus