Overloading PHP Functions

Reply

Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Overloading PHP Functions

 
0
  #1
Mar 11th, 2005
I know it is possible to overload PHP functions as I have seen this done with many of the prebuilt functions. My question is how do you declare an overloaded function? Everytime I try doing this I always get some error about missing arguments (even if there exsist a function with the same number of arguments)
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Overloading PHP Functions

 
0
  #2
Mar 11th, 2005
Found this quote:

PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
and this quote:

Method overloading is however permitted.

<?php
class A {
function A() { }

function ech() {
$a = func_get_args();
for( $t=0;$t<count($a); $t++ ) {
echo $a[$t];
}
}
}

$test = new A();
$test->ech(0,1,2,3,4,5,6,7,8,9);

?>

// output:
// 0123456789
on this page
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 1
Reputation: harrisonad is an unknown quantity at this point 
Solved Threads: 0
harrisonad harrisonad is offline Offline
Newbie Poster

Re: Overloading PHP Functions

 
0
  #3
Mar 14th, 2005
//------------------------
<?php
class A{
function A(){};
}
?>
//---------------------

Dance Instructor is only refering to class constructor, not an example of function overloading.

it is sad though, but php doen't support function overloading.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 3
Reputation: imran.gnit is an unknown quantity at this point 
Solved Threads: 0
imran.gnit imran.gnit is offline Offline
Newbie Poster

Re: Overloading PHP Functions

 
0
  #4
Feb 18th, 2008
i want to know that how to use function overloading in php
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 3
Reputation: imran.gnit is an unknown quantity at this point 
Solved Threads: 0
imran.gnit imran.gnit is offline Offline
Newbie Poster

Re: Overloading PHP Functions

 
0
  #5
Feb 18th, 2008
what is cake php......
is it new technology.......
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 3
Reputation: imran.gnit is an unknown quantity at this point 
Solved Threads: 0
imran.gnit imran.gnit is offline Offline
Newbie Poster

Re: Overloading PHP Functions

 
0
  #6
Feb 18th, 2008
i have to use a .net web service in my php application ...and i have no knowledge how to use .net web service in php but i know how to make a web service in .net...please reply me soon its urgent
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: cburke is an unknown quantity at this point 
Solved Threads: 0
cburke cburke is offline Offline
Newbie Poster

Re: Overloading PHP Functions

 
-1
  #7
Jun 17th, 2009
Actually, method overloading refers to the ability to use the same method/function name in multiple classes such as:

  1. class test1
  2. {
  3.  
  4. private $value;
  5.  
  6. //constructor
  7. function test1(){}
  8.  
  9. //method
  10. function setValue($value){
  11. $this->value=$value;
  12. }
  13.  
  14. }
  15.  
  16.  
  17. class test2
  18. {
  19.  
  20. private $value;
  21.  
  22. //constructor
  23. function test2(){}
  24.  
  25. //method
  26. function setValue($value){
  27. $this->value=$value;
  28. }
  29.  
  30. }

//in use:
  1. <?php
  2. $test1=new test1(); $test1->setValue(1);
  3. $test2=new test2(); $test2->setValue(2);
  4. ?>

As you can see, the same method name was used in both classes and can be called in the same php file. Hope this helps
Last edited by peter_budo; Jun 17th, 2009 at 4:19 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 461
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Overloading PHP Functions

 
0
  #8
Jun 17th, 2009
Originally Posted by paradox814 View Post
I know it is possible to overload PHP functions as I have seen this done with many of the prebuilt functions. My question is how do you declare an overloaded function? Everytime I try doing this I always get some error about missing arguments (even if there exsist a function with the same number of arguments)
It's all about object overloading.

Read this http://www.onlamp.com/pub/a/php/2005...erloading.html
and
http://www.devshed.com/c/a/PHP/Overl...ng-with-PHP-5/
Last edited by adatapost; Jun 17th, 2009 at 12:45 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC