php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48055 Creating class instances by using a variable as class name
Submitted: 2009-04-22 21:51 UTC Modified: 2009-05-08 13:40 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: momrom at freenet dot de Assigned:
Status: Closed Package: Documentation problem
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: momrom at freenet dot de
New email:
PHP Version: OS:

 

 [2009-04-22 21:51 UTC] momrom at freenet dot de
Description:
------------
Its possible to create a new instance of a class by using a variable as class name. But the only place where I read something about this was the first example on page 'OO5 - Patterns'.

I think there should be a note about it in paragraph 'new' on page 'OO5 - The Basics'.

Expected result:
----------------
It is possible to use a variable as classname when creating new instances.

<?php
$classname = 'MyClass';
$instance = new $classname;
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-08 13:40 UTC] danbrown@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC