|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-01-16 12:37 UTC] lisachenko dot it at gmail dot com
Description:
------------
Generator is an internal class, so there shouldn't be an ability to create it by hand. However, the Generator class doesn't have a private constructor and instance of it can be created via ReflectionClass.
Solution: add a private constructor for this class to prevent instantiation (like for Closure class).
Test script:
---------------
$reflection = new ReflectionClass('Generator');
$generator = $reflection->newInstance();
var_dump($generator);
Expected result:
----------------
Expected ReflectionException that restricts an object instantiation.
Fatal error: Uncaught exception 'ReflectionException' with message 'Access to non-public constructor of class Generator'
Actual result:
--------------
Generator object created:
object(Generator)#2 (0) { }
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
@laruence: Imho `new Foo($bar)` and `(new ReflectionClass('Foo'))->newInstance($bar)` should behave the same. So if the constructor throws a fatal error then the constructor invoked through reflection should also throw a fatal error. If reflection doesn't go through get_constructor then it won't work correctly if that handler is overloaded. It just works so well right now because nearly noone overrides get_constructor.