php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #55490
Patch ReflectionClass_newInstanceWithoutConstructor revision 2011-08-25 13:26 UTC by sebastian@php.net
revision 2011-08-25 09:39 UTC by sebastian@php.net
revision 2011-08-25 09:27 UTC by sebastian@php.net
revision 2011-08-25 09:24 UTC by sebastian@php.net

Patch ReflectionClass_newInstanceWithoutConstructor for Reflection related Bug #55490

Patch version 2011-08-25 09:24 UTC

Return to Bug #55490 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions: 2011-08-25 13:26 UTC | 2011-08-25 09:39 UTC | 2011-08-25 09:27 UTC | 2011-08-25 09:24 UTC

Developer: sebastian@php.net

Line 1 (now 1), was 45 lines, now 4 lines
 Index: ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt
 ===================================================================
 --- ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt	(revision 0)
 +++ ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt	(revision 0)
 @@ -0,0 +1,28 @@
 +--TEST--
 +ReflectionClass::newInstanceWithoutConstructor()
 +--CREDITS--
 +Sebastian Bergmann <sebastian@php.net>
 +--FILE--
 +<?php
 +class Foo
 +{
 +    public function __construct()
 +    {
 +        print __METHOD__;
 +    }
 +}
 +
 +$class = new ReflectionClass('Foo');
 +var_dump($class->newInstanceWithoutConstructor());
 +
 +$class = new ReflectionClass('DateTime');
 +var_dump($class->newInstanceWithoutConstructor());
 +--EXPECTF--
 +object(Foo)#%d (0) {
 +}
 +
 +Fatal error: Uncaught exception 'ReflectionException' with message 'Class DateTime is an internal class and cannot be instantiated without invoking its constructor' in %s/tests/ReflectionClass_newInstanceWithoutConstructor.php:%d
 +Stack trace:
 +#0 %s/ReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor()
 +#1 {main}
 +  thrown in %s/ReflectionClass_newInstanceWithoutConstructor.php on line %d
 
 Property changes on: ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt
 ___________________________________________________________________
 Added: svn:keywords
    + Id Rev Revision
 Added: svn:eol-style
    + native
 
  Index: ext/reflection/tests/ReflectionClass_toString_001.phpt
  ===================================================================
  --- ext/reflection/tests/ReflectionClass_toString_001.phpt	(revision 315465)
  +++ ext/reflection/tests/ReflectionClass_toString_001.phpt	(working copy)


         - Parameters [0] {
  @@ -250,6 +250,12 @@
         }
       }
  
  
  +    Method [ <internal:Reflection> public method newInstanceWithoutConstructor ] {
  +
  +      - Parameters [0] {
  +      }


  Index: ext/reflection/php_reflection.c
  ===================================================================
  --- ext/reflection/php_reflection.c	(revision 315465)
  +++ ext/reflection/php_reflection.c	(working copy)
 @@ -4129,6 +4129,25 @@
 @@ -4129,6 +4129,21 @@
   }
   /* }}} */
   
  +/* {{{ proto public stdclass ReflectionClass::newInstanceWithoutConstructor()
Line 82 (now 41), was 21 lines, now 17 lines

  +	zend_class_entry *ce;
  +
  +	METHOD_NOTSTATIC(reflection_class_ptr);
  +	GET_REFLECTION_OBJECT_PTR(ce);
 +
 +	if (ce->type == ZEND_INTERNAL_CLASS) {
 +		zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class and cannot be instantiated without invoking its constructor", ce->name);
 +	}
  +
  +	object_init_ex(return_value, ce);
  +}
  +/* }}} */
  +
   /* {{{ proto public stdclass ReflectionClass::newInstanceArgs([array args])
      Returns an instance of this class */
   ZEND_METHOD(reflection_class, newInstanceArgs)
 @@ -5694,6 +5713,9 @@
 @@ -5694,6 +5709,9 @@
   	ZEND_ARG_INFO(0, args)
   ZEND_END_ARG_INFO()
   
  +ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstanceWithoutConstructor, 0)


  +
   ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_newInstanceArgs, 0, 0, 0)
   	ZEND_ARG_ARRAY_INFO(0, args, 0)
   ZEND_END_ARG_INFO()
 @@ -5742,6 +5764,7 @@
 @@ -5742,6 +5760,7 @@
   	ZEND_ME(reflection_class, getModifiers, arginfo_reflection__void, 0)
   	ZEND_ME(reflection_class, isInstance, arginfo_reflection_class_isInstance, 0)
   	ZEND_ME(reflection_class, newInstance, arginfo_reflection_class_newInstance, 0)
  +	ZEND_ME(reflection_class, newInstanceWithoutConstructor, arginfo_reflection_class_newInstanceWithoutConstructor, 0)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC