php class Database protected static mysql null public static function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class Database {
protected static $mysql = null;
public static function get_connection() {
if(is_null(self::$mysql)) {
self::$mysql = "mysql_connect in the " . __CLASS__;
}
return self::$mysql;
}
}
class News extends Database {
}
class Product extends Database {
}
$news = new News;
$product = new Product;
printf("News mysql: %s\n", $news::get_connection());
printf("Product mysql: %s\n", $news::get_connection());