php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62257 Allow variables in class create
Submitted: 2012-06-08 01:08 UTC Modified: 2015-01-18 04:22 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: valentiny510 at yahoo dot es Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.4.3 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: valentiny510 at yahoo dot es
New email:
PHP Version: OS:

 

 [2012-06-08 01:08 UTC] valentiny510 at yahoo dot es
Description:
------------
I think may be very useful sometimes allowing the use of variables when create some class like this:

$class = 'test';
class $class { }

Sometimes when working with some cms/framework etc.. they have a_very_very_very_long_name_for some_classes and will be more easy (depends of situation) to have an array with shorten name. Ex:

$short_names = array (
    'short1' => 'a_very_long_name_of_some_class',
    'short2' => 'another_very_long_name');
foreach ($short_names as $short => $long)
    class $short extends $long { }
/*endforeach*/;



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-08 01:20 UTC] valentiny510 at yahoo dot es
P.S. Not only for long names.. but also for autoloading/extending multiple classes.. now I let you to imaginate..
 [2012-06-08 23:37 UTC] nikic@php.net
If you want to shorten long names make use of the namespacing support introduced in 5.3. Simply write

    use SomeVery\VeryLong\NameAndMore as ShortName;

and you're done. You can also do this programmatically using class_alias().
 [2012-06-13 19:47 UTC] valentiny510 at yahoo dot es
With the short names was just an example. Imagine one autoload function where you can create classes on the fly:

(pseudofunction)
function autoload( $class )
{
    if ( isset (array($class)))
        include/require $class
    elseif (file_exists($class))
        include $class
    else
        class $class
        {
            function __get( $what ){ return $what 'to be / not to be' }
        }
}

and I can put here more than 10-20 quick examples...
 [2012-10-26 19:41 UTC] dagguh at gmail dot com
Absolutely disagreed.
Downvoting this abomination.
Leave creating anonymous classes to mock frameworks
 [2015-01-08 00:43 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2015-01-08 00:43 UTC] danack@php.net
Hi, it's not clear what you're asking for. The feature request in the original question doesn't appear to be the same as the feature request in the comment. 

Please can you clarify either here, or even better on the PHP internals email list where an RFC could be opened.
 [2015-01-18 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC