Re: wierd function behavior within classes.. Bug?

From: Date: Fri, 25 Jan 2002 04:02:54 +0000
Subject: Re: wierd function behavior within classes.. Bug?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-82025@lists.php.net to get a copy of this message
Remember, You *can* make certain values in a function optional. Place them on the right side of the arg list and give them a default value, like: function myFunction(arg1, arg2, arg3 = "foo", arg4 = "bar") { ... function guts ... } Hope that helps. Mike Frazer "Mike Eheler" <meheler@idearesource.com> wrote in message news:3C50A325.1030901@idearesource.com... > PHP doesn't support that. > > Dunno if it plans to, either. > > There are workarounds.. can't remember exactly how it's done, but I > think I saw it on phpbuilder.com in a tutorial somewhere. > > Mike > > Marc Swanson wrote: > > I'm not sure if this is a known feature in php.. but the following code will > > generate this warning: Warning: Missing argument 2 for foo() in > > /raid/htdocs/test.php on line 7 > > ----------------- > > <? > > class Foo { > > function Foo($bar) { > > // no argument constructor > > echo "One argument Constructor.\n<br>\n"; > > } > > function Foo($bar,$baz) { > > // one argument constructor > > echo "Two argument constructor.\n<br>\n"; > > } > > } > > > > $foo = new Foo("foobared constructor"); > > ?> > > --------------------- > > while simply swapping the functions around removes the warning > > > > --------------------- > > <? > > class Foo { > > function Foo($bar,$baz) { > > // one argument constructor > > echo "Two argument constructor.\n<br>\n"; > > } > > function Foo($bar) { > > // no argument constructor > > echo "One argument Constructor.\n<br>\n"; > > } > > > > } > > $foo = new Foo("foobared constructor"); > > ?> > > ---------------------- > > > > > > This is running on php version 4.0.3pl1 > > Is it supposed to be this way for some reason or is this a bug? I believe I > > found that it happens with all functions within a class (not just > > constructors). > > > > Thanks > > > > > > > > > -- > It is Fortune, not Wisdom, that rules man's life. >

« previous php.general (#82025) next »