php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32790 Overloading builtin functions
Submitted: 2005-04-21 15:10 UTC Modified: 2005-04-25 10:52 UTC
From: timo dot hummel at 4fb dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.4 OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: timo dot hummel at 4fb dot de
New email:
PHP Version: OS:

 

 [2005-04-21 15:10 UTC] timo dot hummel at 4fb dot de
Description:
------------
A very helpful and nice feature for PHP would be to overload builtin functions. As PHP5 now features the functions echo and  print are calling the method __toString if it exists in a class, that feature is still lacking in many other functions where they may be useful (like sprintf, printf, just to name a few).

To prevent that PHP developers have to do alot of work and to provide a general interface, something like the following pseudo code demonstrates overloading builtin functions:

<?php

function myOwnEcho ()
{
  $ts = date("Y-m-d H:i:s");

  print ($ts . " ");

  $num_args = func_num_args();

  for ($i=0; $i < $num_args; $i++)
  {
    print (func_get_arg($i));
  }
}

overload_function("echo", "myOwnEcho");

echo "foo";

?>

Results in:

2004-04-21 15:09:01 foo


I know that echo is a language construct and not a function, it's just been used because most PHP developers use echo for output.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-25 10:52 UTC] derick@php.net
We will not implement this in the core, but you can use the runkit pecl extension - which has similar features.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Sep 17 08:00:02 2025 UTC