Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-18-2003, 09:18 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
overload

i wish you could overload functions in php.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2003, 10:49 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
Hurts readability though. But since that isn't a concern with PHP (mod me as a flamer if you must, but PHP isn't really that nice to look at), I am suprised they didn't include it.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-18-2003, 02:31 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
Quote:
Originally posted by Belisarius
Hurts readability though. But since that isn't a concern with PHP (mod me as a flamer if you must, but PHP isn't really that nice to look at), I am suprised they didn't include it.
lol .. depends who's code you're reading.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2003, 04:08 PM   #4 (permalink)
npa
Code Monkey
 
Join Date: Jul 2003
Location: canada
Posts: 82
npa is on a distinguished road
just do:
Code:
function doSomething0(int a);
function doSomething1(string k);
function doSomething2(object o);
__________________
direct entry file specification.
npa is offline   Reply With Quote
Old 08-18-2003, 07:18 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
sure i could do that .. but then it would be 3 different functions .. and not overloading.

your example would not work if the function i wanted to overload was the constructor of a class. =/ i want overloading in php!!
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2003, 07:19 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
oh, also php isn't sensitive to the variable type .. so it wouldn't really matter for one argument .. just if you were using different amounts of multiple arguments.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2003, 08:51 PM   #7 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
PHP Code:
<?
function blah($foo$bar "")
{
  echo 
"foo is $foo\n";
  if(
$bar != "")
  {
    echo 
"$bar is here too\n";
  }
}

blah("asdf");
blah("fdsa""jkl;");
?>
joe_bruin is offline   Reply With Quote
Old 08-18-2003, 09:15 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
hmm ... good point .. but it's still not the same as making different functions based on what parameters are sent ..

.. although , . i suppose you can test for the second variable and make a different function depending on its value ..

however, what if there is more than 1 pre-defined variable in the argument, you can't determine what variable is being sent .. i mean what if the second variable you send is null, and the third is not .. it only works inline like that.

i suppose ultimately php would have to be data type sensitive .. which would make us give up a lot of little luxuries.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 06:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting