NYCPHP Meetup

NYPHP.org

[nycphp-talk] Class constructor goofs up parameter assignment

Phil Powell phillip.powell at adnet-sys.com
Wed Feb 18 17:40:07 EST 2004


[PHP]
class MySQLQuery {

  var $sql;
  var $mySQLConn;

   function MySQLQuery($sql, $mySQLConn) {
    print_r("From CONSTRUCTOR: sql = $sql<P>");
    $this->sql = $sql;
    $this->mySQLConn =& $mySQLConn;
   }

   // MORE STUFF

}


$sql = "INSERT INTO table (name) VALUES ('Phil')";
print_r($sql);
$query =& new MySQLQuery($sql, $this->getDBConn());
print_r($query);

[/PHP]

Here is the output of the resulting code:

[Code]
INSERT INTO table (name) VALUES ('Phil')

 From CONSTRUCTOR: sql = Resource id #18

mysqlquery Object ( [sql] => Resource id #18 [mySQLConn] => Resource id 
#18 )
[/Code]

How on earth did that happen?? for some strange reason when I assigned 
the parameters to the MySQLQuery constructor everything is fine: the 
first parameter is a String, the second is a Resource Link Object from a 
previous DBConnection Object connect() method call.  Suddenly, in the 
constructor, BOTH parameters are the very same Resource Link Object; 
what happened to my String?

I might be missing something but I can't find it here, any suggestions?

Thanx
Phil

-- 
Phil Powell
Web Developer
  ADNET Systems, Inc.
  11260 Roger Bacon Drive, Suite 403
  Reston, VA  20190-5203
Phone: (703) 709-7218 x107   Cell: (571) 437-4430   FAX: (703) 709-7219
EMail:  Phillip.Powell at adnet-sys.com      AOL IM: SOA Dude







More information about the talk mailing list