|
Posted by Steve on 11/14/06 01:52
"dimo414" <dimo414@gmail.com> wrote in message
news:1163464238.696608.171510@i42g2000cwa.googlegroups.com...
| sTony wrote:
| > I've now got several versions of what is virtually the same function.
I've
| > got a createLink($Link); and a createSpecialLink($Link,$Name) and a
| > createExtraLink($Link,$Extra) and now I've come across a situation where
I
| > need to write yet another almost exactly the same function. I know that
php
| > must support functions with a variable number of parameters, but I have
no
| > idea how to write one. How is this done in php, so I can have just one
| > function that does different things according to the information
supplied.
| >
| > Thanks in advance,
| >
| > sTony
|
| PHP does not in fact allow function overloading, ie same name,
| different signature. But it does allow you to use optional variables,
| simply give them a default value in the parameters list.
|
| For instance, you might make an exponent method, which takes a base and
| a power, like this:
| exponent($base, $power=2)
| {
| // operation
| }
i haven't checked this, but can't you extend a base class and give a
different signature for the same interface?
Navigation:
[Reply to this message]
|