- var_dump: documentation ( source)
<?php
class User{
protected $activeProducts = null;
protected $pdo;
public function __construct(PDO $pdo = null){
$this->pdo = $pdo;
}
public function getProducts(){
if($this->activeProducts){
echo "getting from property (cache)\n";
return $this->activeProducts;
}
//$this->activeProducts = $this->pdo... a long task
echo "getting from db\n";
$this->activeProducts = ['fake','products'];
return $this->activeProducts;
}
}
$user = new User(null);//for tests
var_dump($user->getProducts());
var_dump($user->getProducts());