note 10270 deleted from language.oop by danbrown

From: Date: Sat, 07 Nov 2009 19:04:29 +0000
Subject: note 10270 deleted from language.oop by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162577@lists.php.net to get a copy of this message
Note Submitter: brice at webprojkt dot com ---- Defaulting a function parameter to a variable isn't directly supported, but here's how to get around that: Suppose you have a class: class query { var $sql; var $link; function go ($SQLstring = $this->sql) { return mysql_query($this->sql,$link); } } This doesn't work. Here's the workaround: (function spec): function go ($SQLstring) { if (isset($SQLstring)) { $this->sql = $SQLstring; } return mysql_query($this->sql,$this->link); } This may not be the best example of this, but I thought I'd throw this out for you folks ... should allow support of presetting of an object value and then execution of the method on that, or something like query::go("SELECT ..."); Enjoy! p.s. (in this case query::go wouldn't work because it is coded with $this->link, but if you wanted to just use the default connection, it'd work fine :)

« previous php.notes (#162577) next »