php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53215 Method overload on PHP
Submitted: 2010-11-01 01:34 UTC Modified: 2010-11-01 18:27 UTC
From: jonimane at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS: Windows XP
Private report: No CVE-ID: None
 [2010-11-01 01:34 UTC] jonimane at gmail dot com
Description:
------------
Can you implements overload methods?

look test script x.x

my english is so so bad, sorry.

if you didn't understand me, i can explain you x.x

thx

Test script:
---------------
<?php
class Test
{
  public function hello()
  {
    echo "hello";
  }

  public function hello($name)
  {
    echo "hello {$name}";
  }
}

$c = new Test;
$c->hello(); // print "hello"
$c->hello("PHP"); // print "hello PHP"
?>

Expected result:
----------------
don't give errors and method overload work

Actual result:
--------------
Fatal error: Cannot redeclare Test::hello() in C:\...\Test.php on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-01 04:55 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-11-01 04:55 UTC] cataphract@php.net
Not adequate to PHP for several reasons:

* Type of arguments cannot be provided expect in limited circumstances, and even then it's not required.
* The only differentiating factor would be the number of arguments, but in PHP a function can take more arguments than it declares, so even then...
 [2010-11-01 18:27 UTC] jonimane at gmail dot com
hm =/

To polymorphism would greatly help

function t(Test $t)
{
  ...
}

function t(NoTest $t)
{
  ...
}

so, thank you anyway =]

if it were implemented would be great *-*

thx again =]
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 01:01:30 2024 UTC