note 10270 added to Classes and Objects

From: Date: Fri, 22 Dec 2000 02:23:56 +0000
Subject: note 10270 added to Classes and Objects
Groups: php.notes 
Request: Send a blank email to php-notes+get-9015@lists.php.net to get a copy of this message
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 :) http://www.php.net/manual/language.oop.php

« previous php.notes (#9015) next »