php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70643 Allow update of class alias
Submitted: 2015-10-05 14:40 UTC Modified: 2020-01-08 16:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: remyfox at hotmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Next Major Version OS: irrelevant
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: remyfox at hotmail dot com
New email:
PHP Version: OS:

 

 [2015-10-05 14:40 UTC] remyfox at hotmail dot com
Description:
------------
Since a class alias is assigned during run time, I suppose it would make sense to allow a class alias's update.

Use case:
E.g. in a system where multiple classes of different code versions (temporarily) exist to ensure backward compatibility when importing a number of updates. The versions of the class could all be put in separate temporarily generated uniquely named namespaces. During the execution of the updates, the class alias could be updated once it reaches an update which needs to use a newer version of a class that was also used by previous updates - albeit in an older state.

Might be a good idea to include this in PHP 7. It seems like a small enhancement.

Test script:
---------------
class A {}
class B {}

class_alias("A", "X");

class_alias("B", "X");

Expected result:
----------------
Class alias X becomes B's alias.

Actual result:
--------------
Fatal error: Cannot redeclare class A

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-08 16:01 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2020-01-08 16:01 UTC] nikic@php.net
We're definitely not going to support this, as it makes inheritance checks unsound.

If you want to use the same library in multiple versions (or more typically, to avoid phar conflicts) you might want to take a look at https://github.com/humbug/php-scoper.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 17:01:29 2024 UTC