Req #68470 [Fbk->Opn]: Wish:Add prefix to field name while mysqli_result::fetch_object
| From: | eglic dot csdn at gmail dot com | Date: | Mon, 15 May 2017 09:36:50 +0000 |
| Subject: | Req #68470 [Fbk->Opn]: Wish:Add prefix to field name while mysqli_result::fetch_object | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209124@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68470&edit=1
ID: 68470
User updated by: eglic dot csdn at gmail dot com
Reported by: eglic dot csdn at gmail dot com
Summary: Wish:Add prefix to field name while
mysqli_result::fetch_object
-Status: Feedback
+Status: Open
Type: Feature/Change Request
Package: MySQLi related
Operating System: All
PHP Version: 5.6.3
Block user comment: N
Private report: N
New Comment:
NOT stdClass. for example :
class UserEntity {
function __construct(){
$this->name = ''; // Default value from mysql schema
$this->status = 1; // default value from mysql schema
}
public $name;
public $status;
}
////////////////////////////////////
Scene 1:
$u = new UserEntity();
$u->name = 'test';
$u->status = 0;
$userFactory->Save($u);
this is correct.
////////////////////////////////////
Scene 2:
$u = $result->fetch_object('UserEntity');
var_dump($u);
output :
$u->name is '';
$u->status is 1;
Previous Comments:
------------------------------------------------------------------------
[2017-05-15 09:01:02] fjanisze@php.net
Can you provide some more use cases for this suggestion? Can you also sketch some specification
detail for it? Also, sorry but I do not understand you question, perhaps try stackoverflow.
------------------------------------------------------------------------
[2014-11-21 10:47:59] eglic dot csdn at gmail dot com
Description:
------------
I tought to improve fetch_object such as follow code is useful:
mysqli_result::fetch_object ([ string $class_name = "stdClass" [[, string
$field_name_prefix = ''], array $params ]] )
example code :
$result = $mysqli->query("select id,name from user limit 1");
$user = $result->fetch_object('stdClass','__');
var_dump($user);
output :
object stdClass {
$__id = 1;
$__name = 'someone';
}
-----------------------------------
in addition , i have a question :
why call __constructor at the last in this method?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68470&edit=1