helly           Tue Feb 21 00:37:39 2006 UTC

  Added files:                 
    /php-src/ext/reflection/tests       008.phpt 

  Modified files:              
    /php-src/ext/reflection     php_reflection.c 
  Log:
  - Add ReflectionProperty::getDefaultValue()
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/php_reflection.c?r1=1.211&r2=1.212&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.211 
php-src/ext/reflection/php_reflection.c:1.212
--- php-src/ext/reflection/php_reflection.c:1.211       Mon Feb 20 23:31:29 2006
+++ php-src/ext/reflection/php_reflection.c     Tue Feb 21 00:37:39 2006
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.211 2006/02/20 23:31:29 johannes Exp $ */
+/* $Id: php_reflection.c,v 1.212 2006/02/21 00:37:39 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1106,15 +1106,17 @@
        zval *classname;
        property_reference *reference;
        char *class_name, *prop_name;
+       zend_uchar utype = UG(unicode) ? IS_UNICODE : IS_STRING;
 
-       zend_u_unmangle_property_name(UG(unicode)?IS_UNICODE:IS_STRING, 
prop->name, &class_name, &prop_name);
-
+       zend_u_unmangle_property_name(utype, prop->name, &class_name, 
&prop_name);
+       
        if (!(prop->flags & ZEND_ACC_PRIVATE)) {
                /* we have to seach the class hierarchy for this (implicit) 
public or protected property */
                zend_class_entry *tmp_ce = ce;
                zend_property_info *tmp_info;
+               int prop_name_len = UG(unicode) ? u_strlen((UChar*)prop_name) : 
strlen(prop_name);
                
-               while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, 
prop_name, strlen(prop_name) + 1, (void **) &tmp_info) != SUCCESS) {
+               while (tmp_ce && zend_u_hash_find(&tmp_ce->properties_info, 
utype, prop_name, prop_name_len + 1, (void **) &tmp_info) != SUCCESS) {
                        ce = tmp_ce;
                        prop = tmp_info;
                        tmp_ce = tmp_ce->parent;
@@ -3716,6 +3718,36 @@
 }
 /* }}} */
 
+/* {{{ proto public mixed ReflectionProperty::getDefaultValue()
+   Returns the default value of the property. */
+ZEND_METHOD(reflection_property, getDefaultValue)
+{
+       reflection_object *intern;
+       property_reference *ref;
+       HashTable *prop_defaults;
+       zval **zdef, *zv;
+       zend_uchar utype = UG(unicode) ? IS_UNICODE : IS_STRING;
+
+       METHOD_NOTSTATIC_NUMPARAMS(reflection_property_ptr, 0);
+       GET_REFLECTION_OBJECT_PTR(ref);
+
+       if (ref->prop->flags & ZEND_ACC_STATIC) {
+               prop_defaults = &ref->ce->default_static_members;
+       } else {
+               prop_defaults = &ref->ce->default_properties;
+       }
+
+       if (zend_u_hash_quick_find(prop_defaults, utype, ref->prop->name, 
ref->prop->name_length+1, ref->prop->h, (void**)&zdef) == SUCCESS) {
+               ALLOC_ZVAL(zv);
+               *zv = **zdef;
+               zval_copy_ctor(zv);
+               INIT_PZVAL(zv);
+               zval_update_constant(&zv, (void*)1 TSRMLS_CC);
+               RETURN_ZVAL(zv, 1, 1);
+       }
+}
+/* }}} */
+
 /* {{{ proto public int ReflectionProperty::getModifiers()
    Returns a bitfield of the access modifiers for this property */
 ZEND_METHOD(reflection_property, getModifiers)
@@ -4287,6 +4319,7 @@
        ZEND_ME(reflection_property, isStatic, NULL, 0)
        ZEND_ME(reflection_property, isDefault, NULL, 0)
        ZEND_ME(reflection_property, getModifiers, NULL, 0)
+       ZEND_ME(reflection_property, getDefaultValue, NULL, 0)
        ZEND_ME(reflection_property, getDeclaringClass, NULL, 0)
        ZEND_ME(reflection_property, getDocComment, NULL, 0)
        {NULL, NULL, NULL}
@@ -4433,7 +4466,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Reflection", "enabled");
 
-       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.211 
2006/02/20 23:31:29 johannes Exp $");
+       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.212 
2006/02/21 00:37:39 helly Exp $");
 
        php_info_print_table_end();
 } /* }}} */

http://cvs.php.net/viewcvs.cgi/php-src/ext/reflection/tests/008.phpt?view=markup&rev=1.1
Index: php-src/ext/reflection/tests/008.phpt
+++ php-src/ext/reflection/tests/008.phpt
--TEST--
ReflectionProperty::getDefaultValue()
--FILE--
<?php


class root
{
        public    $rPub = "rPub";
        public    $xPub = "xPub";
        protected $rPro = "rPro";
        protected $xPro = "xPub";
        private   $rPri = "rPri";
        private   $xPri = "xPri";
        
        static public $stat = "rStat";
}

class derived extends root
{
        public    $dPub = "dPub";
        public    $xPub = "nPub";
        protected $dPro = "dPro";
        protected $xPro = "nPub";
        private   $dPri = "dPri";
        private   $xPri = "nPri";       
}

function show_prop($p)
{
        echo "{$p->class}::{$p->name} = " . $p->getDefaultValue() . "\n";
}

function show_class($c)
{
        echo "===$c===\n";

        $r = new ReflectionClass($c);

        foreach($r->getProperties() as $p)
        {
                show_prop($p);
        }
}

show_class("root");
show_class("derived");

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
===root===
root::rPub = rPub
root::xPub = xPub
root::rPro = rPro
root::xPro = xPub
root::rPri = rPri
root::xPri = xPri
root::stat = rStat
===derived===
derived::dPub = dPub
derived::xPub = nPub
derived::dPro = dPro
derived::xPro = nPub
derived::dPri = dPri
derived::xPri = nPri
derived::rPub = rPub
derived::rPro = rPro
derived::stat = rStat
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to