Vaag probleem met protected
Ik ben een heel raar probleem tegen gekomen, en het lijkt meer op een bug, maar zal het toch aan jullie voorschotelen.
( Probleem is trouwens alleen op mijn host, niet op localhost )
Ik heb deze classe ( verkort ) :
Code (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class MFW_Registry implements ArrayAccess, Iterator, Countable {
protected $globals = array() ;
// Magic methods
public function __construct() {
}
public function __destruct() {
}
public function __get( $key ) {
return $this->offsetGet ( $key );
}
public function __set ( $key, $value ) {
$this->offsetSet ( $key, $value );
}
// IMPLEMENTATIONS
//-- ArrayAccess
public function offsetExists ( $offset ) {
//------ HIER GAAT HET FOUT !.. HIJ HERKENT $this->globals niet
return isset ( $this->globals [ $offset ] );
}
public function offsetGet ( $offset ) {
//------ ZELFDE GELDT HIER
if ( $this->offsetExists ( $offset ) ) {
return $this->globals [ $offset ];
} else {
throw new RangeException("Index " . $offset . " out of bounds in ". __CLASS__ . "::offsetGet");
}
}
}
?>
class MFW_Registry implements ArrayAccess, Iterator, Countable {
protected $globals = array() ;
// Magic methods
public function __construct() {
}
public function __destruct() {
}
public function __get( $key ) {
return $this->offsetGet ( $key );
}
public function __set ( $key, $value ) {
$this->offsetSet ( $key, $value );
}
// IMPLEMENTATIONS
//-- ArrayAccess
public function offsetExists ( $offset ) {
//------ HIER GAAT HET FOUT !.. HIJ HERKENT $this->globals niet
return isset ( $this->globals [ $offset ] );
}
public function offsetGet ( $offset ) {
//------ ZELFDE GELDT HIER
if ( $this->offsetExists ( $offset ) ) {
return $this->globals [ $offset ];
} else {
throw new RangeException("Index " . $offset . " out of bounds in ". __CLASS__ . "::offsetGet");
}
}
}
?>
Het is maar een verkorte versie, alle interfaces zijn gewoon geimplementeerd.
Het probleem is dus dat tie $this->globals niet kent, ik krijg namelijk deze foutmelding:
Quote:
Fatal error: Uncaught exception 'RangeException' with message 'Index globals out of bounds in MFW_Registry::offsetGet' in /ergens/class.MFW_Registry.php:87 Stack trace: #0 /ergens/class.MFW_Registry.php(15): MFW_Registry->offsetGet('globals') #1 /ergens/class.MFW_Registry.php(77): MFW_Registry->__get('globals') #2 /ergens/class.MFW_Registry.php(44): MFW_Registry->offsetExists('database') #3 /ergens/config.php(42): MFW_Registry->add('database', Object(DB_MySQL)) #4 /ergens/index.php(4): require_once('/mounted-storag...') #5 {main} thrown in /ergens/class.MFW_Registry.php on line 87
Als ik $globals private of public maakt werkt het wel.
Weet iemand wat het probleem is?
Gewijzigd op 01/01/1970 01:00:00 door Stien ss
mss is het handig als we weten wat lijn 87 is;p
Het staat al in het script, maar de fout zit bij offsetExists()
@martijn: ook dat zou het kunnen zijn. Het vreemde is dat het wel werkt op localhost
Gewijzigd op 01/01/1970 01:00:00 door Martijn B