|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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*/;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 21 21:00:01 2025 UTC |
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().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...