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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 01 10:01:29 2024 UTC