Re: Object Constructors -- Part II

From: Date: Sat, 16 Sep 2000 18:38:17 +0000
Subject: Re: Object Constructors -- Part II
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17020@lists.php.net to get a copy of this message
If you need differing numbers of arguments in your constructors, you can use the variable-length argument lists functions. See, for example, http://php.net/manual/function.func-num-args.php in the documentation. Bill On Fri, 15 Sep 2000, Rasmus Lerdorf wrote: > On Fri, 15 Sep 2000, The Captain wrote: > > > Well, it turns out that it was my own terrible typo that was causing the > > error on a constructor with passed variables. > > > > However... I am getting another error with constructor overloading. > > > > Here's a code sample: > > > > class openFile { > > var $myfile; > > > > function openFile() { > > $this->myFile = "/var/logs/somefile"; > > } > > > > function openFile($f) { > > $this->myFile = $f; > > } > > > > } > > > > > > this is how i'm newing the object: > > > > $of = new of; > > > > I am getting this error from PHP though: > > > > Warning: Missing argument 1 for log() in log.inc on line 8 > > > > I wanted to have both constructors in there so I could have a "default" > > filename as well as one i could specify when the object gets created. > > This is a good example of a really silly thing people do with > overloading. The proper way to do this is: > > class openFile { > var $myfile; > > function openFile($f = "/var/logs/somefile") { > $this->myFile = $f; > } > > } > > Nice and clean. > > -Rasmus > > --

« previous php.general (#17020) next »