Bug #66377 [Opn->Nab]: closure instantiation is not allowed when return string class name

From: Date: Tue, 31 Dec 2013 22:04:44 +0000
Subject: Bug #66377 [Opn->Nab]: closure instantiation is not allowed when return string class name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183519@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66377&edit=1 ID: 66377 Updated by: requinix@php.net Reported by: dev at nicolab dot net Summary: closure instantiation is not allowed when return string class name -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: Debian 7 PHP Version: 5.4.23 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php "new" only supports literal names, variable-variables (one level of indirection only), and object instances (as if you get_class()ed them). That means no closures, which are objects and thus why new tried to create an instance of Closure. Meanwhile the parentheses you're using are not to invoke the closure but to pass arguments to the class's constructor. $classname = $class(); new $classname(); Previous Comments: ------------------------------------------------------------------------ [2013-12-31 21:28:39] dev at nicolab dot net Description: ------------ Hello, closure instantiation is not allowed when the closure return a string class name. My PHP package : $ php -v PHP 5.4.4-14+deb7u7 (cli) (built: Dec 12 2013 08:42:07) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans Test script: --------------- $class = function(){ return '\StdClass'; }; new $class(); Expected result: ---------------- (object) instance of \StdClass Actual result: -------------- Catchable fatal error: Instantiation of 'Closure' is not allowed in /var/www/file.php on line 30 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66377&edit=1

« previous php.bugs (#183519) next »