because when I declare a singleton to handle a single instance, when performing the operation with the same instance at the end it does not work, because select and from does not concatenate the variable to be able to show it in the same instance?
<?php
class singleton{
protected static $instance = null;
public static $sql = null;
public function __construct(){}
private final function __clone() { }
public static function instance() {
if ( self::$instance == NULL ) {
self::$instance = new self();
}
return self::$instance;
}
public function select(){
self::$sql = "SELECT * <br />";
return new static;
}
public function from(){
self::$sql .= "FROM TABLE1 <br />";
return new static;
}
}
singleton::instance()->select();
singleton::instance()->from();
var_dump( singleton::instance()->sql );
The result is:
Null
But I expect result: SELECT * <br /> FROM TABLE1 <br />
How can I keep the values within the same instance?