【发布时间】:2016-06-16 21:10:32
【问题描述】:
我正在学习 OOP。我的问题基于以下代码。每次使用$query_value->GetName() 或$query_value->GetId() 在index.php 中返回值。
是不是因为$query_value而每次都运行MySQL查询?
在 Class.php 中
<?php
class OOP{
public $name,$id,$password
public function query(){
/* Query Performed
rowCount() = 1 */
$this->name = returned row value;
$this->id = returned row value;
$this->password= returned row value;
return $this; // [NOTE THIS ($this)]
}
public function GetName(){
return $this->name;
}
public function GetId(){
return $this->id;
}
}
在 index.php 中
<?php
$test= new OOP();
$query_value = $test->query();
// now returning values
echo $query_value->GetName();
/// Some Html
echo $query_value->GetId();
?>
【问题讨论】: