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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david at tulloh dot id dot au
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC