php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62520 Feature request: Anonymous Class
Submitted: 2012-07-10 05:10 UTC Modified: 2016-01-15 12:37 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: k at webnfo dot com Assigned: danack (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: k at webnfo dot com
New email:
PHP Version: OS:

 

 [2012-07-10 05:10 UTC] k at webnfo dot com
Description:
------------
The syntax imagined as below (Define And Initiate An Anonymous Class):

$object = (new class($param1, $param1){
  public $var1 = 'abc'

  public function test(){
    echo $this->var1;
  }
});

$object->test();

out: 'abc'

============ Or Alternatively ===================

(new class($param1, $param1){
  public $var1 = 'abc'

  public function test(){
    echo $this->var1;
  }
})->test();

out: 'abc'




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-08 22:12 UTC] php at mcq8 dot be
This actually works in php7 (https://wiki.php.net/rfc/anonymous_classes)
 [2016-01-15 12:37 UTC] danack@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: danack
 [2016-01-15 12:37 UTC] danack@php.net
Anonymous classes were implemented in PHP 7.

http://php.net/manual/en/language.oop5.anonymous.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 15:01:31 2025 UTC