php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36221 new __CLASS__() would be nice
Submitted: 2006-01-31 08:18 UTC Modified: 2006-02-01 03:35 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: david at tulloh dot id dot au Assigned: helly (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2006-01-31 08:18 UTC] david at tulloh dot id dot au
Description:
------------
It would be nice if, $object = new __CLASS__(); was supported.

Currently this throws a parse/syntax error, 
Parse error: syntax error, unexpected T_CLASS_C, expecting T_STRING or T_VARIABLE or '$' in ...

This does work as expected,
$foo = __CLASS__;
$object = new $foo();


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-01 01:21 UTC] helly@php.net
Use 'self' instead:

php -r 'class t{static function f(){ var_dump(new self);}} t::f();'
 [2006-02-01 03:35 UTC] david at tulloh dot id dot au
excellent, thankyou
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 12:01:31 2024 UTC