php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47213 include rename_function() in standard library
Submitted: 2009-01-25 16:35 UTC Modified: 2009-01-25 21:49 UTC
From: rasmus at mindplay dot dk Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.8 OS: all
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: rasmus at mindplay dot dk
New email:
PHP Version: OS:

 

 [2009-01-25 16:35 UTC] rasmus at mindplay dot dk
Description:
------------
Please consider including this function in the standard library:

http://us3.php.net/rename_function

This would enable techniques as shown below.

I know this is a duplicate of feature request #37078, which was bluntly rejected without explanation, before anyone had a chance to review or comment on this idea.

Reproduce code:
---------------
<?php

// example -
// install an autoload handler that preserves an existing handler:

if (function_exists('__autoload')) {
  rename_function('__autoload', '__autoload_old');
}

function __autoload($class_name) {
  if (function_exists('__autoload_old') {
    try {
      __autoload_old($class_name);
    catch ($e) {
      // my own autoloader here..
    }
  }
}

?>

Another example would be the ability to extend existing PHP functions with new functionality, like calculating default arguments or enhancing the behavior of certain functions. Example: the array_chunk function only works with real arrays - you could override it with a function that works with iterable objects as well.

Expected result:
----------------
This would work - you could override this magic function and preserve any existing autoloader.

This would enable you to combine autoloaders from different projects.

Actual result:
--------------
The function is not generally available on standard PHP installations.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-25 21:49 UTC] johannes@php.net
It's here for people who _really_ want it, but we certainly won't make this a default function as 99% of the probable use cases are bad deign of PHP applications or other mistakes. In your case see spl_autoload_register() which does exactly what you want.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 10:01:32 2024 UTC