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
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: 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: Thu May 08 05:01:28 2025 UTC