felipe                                   Wed, 02 Jun 2010 15:29:42 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300096

Log:
- Added ReflectionClass::isCloneable() [DOC]

Changed paths:
    U   php/php-src/trunk/UPGRADING
    U   php/php-src/trunk/ext/reflection/php_reflection.c
    A   
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt
    A   
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_002.phpt

Modified: php/php-src/trunk/UPGRADING
===================================================================
--- php/php-src/trunk/UPGRADING 2010-06-02 15:27:38 UTC (rev 300095)
+++ php/php-src/trunk/UPGRADING 2010-06-02 15:29:42 UTC (rev 300096)
@@ -228,7 +228,8 @@

      h. New methods

-       -
+       - Reflection:
+         - ReflectionClass::isCloneable()

      i. New class constants


Modified: php/php-src/trunk/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/trunk/ext/reflection/php_reflection.c   2010-06-02 15:27:38 UTC 
(rev 300095)
+++ php/php-src/trunk/ext/reflection/php_reflection.c   2010-06-02 15:29:42 UTC 
(rev 300096)
@@ -3987,6 +3987,39 @@
 }
 /* }}} */

+/* {{{ proto public bool ReflectionClass::isCloneable()
+   Returns whether this class is cloneable */
+ZEND_METHOD(reflection_class, isCloneable)
+{
+       reflection_object *intern;
+       zend_class_entry *ce;
+       zval obj;
+
+       if (zend_parse_parameters_none() == FAILURE) {
+               return;
+       }
+       GET_REFLECTION_OBJECT_PTR(ce);
+       if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | 
ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
+               RETURN_FALSE;
+       }
+       if (intern->obj) {
+               if (ce->clone) {
+                       RETURN_BOOL(ce->clone->common.fn_flags & 
ZEND_ACC_PUBLIC);
+               } else {
+                       RETURN_BOOL(Z_OBJ_HANDLER_P(intern->obj, clone_obj) != 
NULL);
+               }
+       } else {
+               object_init_ex(&obj, ce);
+               if (ce->clone) {
+                       RETVAL_BOOL(ce->clone->common.fn_flags & 
ZEND_ACC_PUBLIC);
+               } else {
+                       RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL);
+               }
+               zval_dtor(&obj);
+       }
+}
+/* }}} */
+
 /* {{{ proto public bool ReflectionClass::isInterface()
    Returns whether this is an interface or a class */
 ZEND_METHOD(reflection_class, isInterface)
@@ -5693,6 +5726,7 @@
        ZEND_ME(reflection_class, isInternal, arginfo_reflection__void, 0)
        ZEND_ME(reflection_class, isUserDefined, arginfo_reflection__void, 0)
        ZEND_ME(reflection_class, isInstantiable, arginfo_reflection__void, 0)
+       ZEND_ME(reflection_class, isCloneable, arginfo_reflection__void, 0)
        ZEND_ME(reflection_class, getFileName, arginfo_reflection__void, 0)
        ZEND_ME(reflection_class, getStartLine, arginfo_reflection__void, 0)
        ZEND_ME(reflection_class, getEndLine, arginfo_reflection__void, 0)

Added: 
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt 
                        (rev 0)
+++ php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt 
2010-06-02 15:29:42 UTC (rev 300096)
@@ -0,0 +1,69 @@
+--TEST--
+Testing ReflectionClass::isCloneable()
+--FILE--
+<?php
+
+class foo {
+}
+$foo = new foo;
+
+print "User class\n";
+$obj = new ReflectionClass($foo);
+var_dump($obj->isCloneable());
+$obj = new ReflectionObject($foo);
+var_dump($obj->isCloneable());
+$h = clone $foo;
+
+class bar {
+       private function __clone() {
+       }
+}
+$bar = new bar;
+print "User class - private __clone\n";
+$obj = new ReflectionClass($bar);
+var_dump($obj->isCloneable());
+$obj = new ReflectionObject($bar);
+var_dump($obj->isCloneable());
+$h = clone $foo;
+
+print "Closure\n";
+$closure = function () { };
+$obj = new ReflectionClass($closure);
+var_dump($obj->isCloneable());
+$obj = new ReflectionObject($closure);
+var_dump($obj->isCloneable());
+$h = clone $closure;
+
+print "Internal class - SimpleXMLElement\n";
+$obj = new ReflectionClass('simplexmlelement');
+var_dump($obj->isCloneable());
+$obj = new ReflectionObject(new simplexmlelement('<test></test>'));
+var_dump($obj->isCloneable());
+$h = clone new simplexmlelement('<test></test>');
+
+print "Internal class - XMLWriter\n";
+$obj = new ReflectionClass('xmlwriter');
+var_dump($obj->isCloneable());
+$obj = new ReflectionObject(new XMLWriter);
+var_dump($obj->isCloneable());
+$h = clone new xmlwriter;
+
+?>
+--EXPECTF--
+User class
+bool(true)
+bool(true)
+User class - private __clone
+bool(false)
+bool(false)
+Closure
+bool(true)
+bool(true)
+Internal class - SimpleXMLElement
+bool(true)
+bool(true)
+Internal class - XMLWriter
+bool(false)
+bool(false)
+
+Fatal error: Trying to clone an uncloneable object of class XMLWriter in %s on 
line %d


Property changes on: 
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: 
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_002.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_002.phpt 
                        (rev 0)
+++ php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_002.phpt 
2010-06-02 15:29:42 UTC (rev 300096)
@@ -0,0 +1,25 @@
+--TEST--
+Testing ReflectionClass::isCloneable() with non instantiable objects
+--FILE--
+<?php
+
+trait foo {
+}
+$obj = new ReflectionClass('foo');
+var_dump($obj->isCloneable());
+
+abstract class bar {
+}
+$obj = new ReflectionClass('bar');
+var_dump($obj->isCloneable());
+
+interface baz {
+}
+$obj = new ReflectionClass('baz');
+var_dump($obj->isCloneable());
+
+?>
+--EXPECT--
+bool(false)
+bool(false)
+bool(false)


Property changes on: 
php/php-src/trunk/ext/reflection/tests/ReflectionClass_isCloneable_002.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

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

Reply via email to