note 83595 added to function.mysql-fetch-object

From: Date: Tue, 03 Jun 2008 22:19:37 +0000
Subject: note 83595 added to function.mysql-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-140094@lists.php.net to get a copy of this message
<?php class Test { public $go ; private $id ; function show() { return "id: {$this->id} go: {$this->go}" ; } function __construct() { echo "in __construct() ". $this->show() ."\n" ; $this->go = uniqid() ; } } if (! ($res = mysql_query('SELECT * FROM test', $db))) { die('Invalid query: ' . mysql_error() . "\n"); } while($obj = mysql_fetch_object($res, 'Test') ){ echo "outside ________ ". $obj->show() ."\n\n"; } ?> This code gives the result: in __construct() id: 1 go: first outside ________ id: 1 go: 4845bd99ca2e3 in __construct() id: 2 go: second outside ________ id: 2 go: 4845bd99ca2fd It means that __construct() is invoked after filling fields with data from database, eg. it can be used to change strings into integers. ---- Server IP: 82.177.164.100 Probable Submitter: 62.87.243.122 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-object.php Edit -- https://master.php.net/note/edit/83595 Del: integrated -- https://master.php.net/note/delete/83595/integrated Del: useless -- https://master.php.net/note/delete/83595/useless Del: bad code -- https://master.php.net/note/delete/83595/bad+code Del: spam -- https://master.php.net/note/delete/83595/spam Del: non-english -- https://master.php.net/note/delete/83595/non-english Del: in docs -- https://master.php.net/note/delete/83595/in+docs Del: other reasons-- https://master.php.net/note/delete/83595 Reject -- https://master.php.net/note/reject/83595 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140094) next »