Ability to change class name #273

msavery opened this Issue Nov 16, 2012 · 2 comments


None yet
3 participants

msavery commented Nov 16, 2012

new Redis() to new SomethingElse()

I don't think this should be handled by the PhpRedis extension.

You can create an alias for a user defined class/interface easily, like this:

class User {}

class_alias( 'User', 'UserAlias' );

$user = new User;
var_dump( $user instanceof User ); // true
var_dump( $user instanceof UserAlias ); // true

$userAlias = new UserAlias;
var_dump( $userAlias instanceof User ); // true
var_dump( $userAlias instanceof UserAlias ); // true

However, you can NOT create an alias of built-in classes/interfaces:

// This results in a "PHP Warning", because class "Exception" is a built-in class.
class_alias( 'Exception', 'ExceptionAlias' );

PHP Warning: First argument of class_alias() must be a name of user defined class in /home/jason/Projects/Sandbox/index.php on line 16
PHP Stack trace:
PHP 1. {main}() /home/jason/Projects/Sandbox/index.php:0
PHP 2. class_alias() /home/jason/Projects/Sandbox/index.php:16

This is a restriction of the PHP language, it should not be handle by the PhpRedis extension. If you really want this feature why not request for this feature at php.net.

Btw, you can always do this:

class AnotherName extends Redis {}

new AnotherName();

Hope this helps :)

msavery commented Nov 26, 2012

Yeah it does help actually. Thanks a million.

nicolasff closed this Feb 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment