Eerst maar eens wat source:
test.php
test2.php
Error: Fatal error: Cannot redeclare class test2 in f:\dutchmega\www\test2.php on line 7
Toelichting: Class test included test2 class en roept het aan d.m.v PHP5 singleton-pattern. (Lees: static functie
)
In test2 class roep ik de instantie van de test class weer aan maar hij pakt een andere instantie waardoor test2.php nog een keer geincluded wordt..
Het punt is, getInstance() haalt niet de goede instantie op maar dat zou gewoon goed moeten zijn? Want ik roep de class gewoon statisch aan..Ik snap niet dat als je het vanuit een classfunctie roept, dat het gewoon niet werkt.. PHP-bug of wat anders
* Dutchmega draait trouwens PHP 5.02
EDIT: Ook @ laatste snapshots..
test.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| <?php ini_set ("zend.ze1_compatibility_mode", "0"); error_reporting (E_ALL|E_STRICT); class test { public static $instance = NULL; public $variable = ":P"; public static function getInstance() { if (self::$instance == NULL) { self::$instance = new test(); } return self::$instance; } public function __construct () { $this->variable = ":D"; $this->load(); } private function load () { include ("test2.php"); $class = test2::getInstance(); } } test::getInstance(); ?> |
test2.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <?php ini_set ("zend.ze1_compatibility_mode", "0"); error_reporting (E_ALL|E_STRICT); class test2 { public static $instance = NULL; public static function getInstance() { if (self::$instance == NULL) { self::$instance = new test2(); } return self::$instance; } private function __construct () { // Probleem is deze regel :) print_r (test::getInstance()); echo ":D"; } } ?> |
Error: Fatal error: Cannot redeclare class test2 in f:\dutchmega\www\test2.php on line 7
Toelichting: Class test included test2 class en roept het aan d.m.v PHP5 singleton-pattern. (Lees: static functie
In test2 class roep ik de instantie van de test class weer aan maar hij pakt een andere instantie waardoor test2.php nog een keer geincluded wordt..
Het punt is, getInstance() haalt niet de goede instantie op maar dat zou gewoon goed moeten zijn? Want ik roep de class gewoon statisch aan..Ik snap niet dat als je het vanuit een classfunctie roept, dat het gewoon niet werkt.. PHP-bug of wat anders
* Dutchmega draait trouwens PHP 5.02
EDIT: Ook @ laatste snapshots..
[ Voor 17% gewijzigd door Dutchmega op 26-11-2004 22:20 ]