21279 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 440 Views |
-
Singleton Class

5 June 2011 at 7:55am Last edited: 5 June 2011 7:58am
I tried to build a singleton class, but it doesn't work. The function i used do not return anything.
Code on Pastie.org (Hope it works)<?php
//-----------------singleton class------------------------
final class SearchResult {private static $instance = NULL;
private function __construct() {
}public static function getInstance() {
if (self::$instance === NULL) {
self::$instance = new self;
}
return self::$instance;
}public function getResultTable(){
return 'Test- Result';
}}
// try to use the class
// [...]
function Test(){
$searchResult = SearchResult::getInstance();
return 'Result: '.$searchResult->getResultTable;
}
// [...]?>
| 440 Views | ||
|
Page:
1
|
Go to Top |


