~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to tests/classes/array_access_004.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
ZE2 ArrayAccess::offsetGet ambiguties
 
3
--FILE--
 
4
<?php
 
5
class object implements ArrayAccess {
 
6
 
 
7
        public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
 
8
 
 
9
        function offsetExists($index) {
 
10
                echo __METHOD__ . "($index)\n";
 
11
                return array_key_exists($index, $this->a);
 
12
        }
 
13
        function offsetGet($index) {
 
14
                echo __METHOD__ . "($index)\n";
 
15
                switch($index) {
 
16
                case 1:
 
17
                        $a = 'foo';
 
18
                        return $a . 'Bar';
 
19
                case 2:
 
20
                        static $a=1;
 
21
                        return $a;
 
22
                }
 
23
                return $this->a[$index];
 
24
        }
 
25
        function offsetSet($index, $newval) {
 
26
                echo __METHOD__ . "($index,$newval)\n";
 
27
                if ($index==3) {
 
28
                        $this->cnt = $newval;
 
29
                }
 
30
                return $this->a[$index] = $newval;
 
31
        }
 
32
        function offsetUnset($index) {
 
33
                echo __METHOD__ . "($index)\n";
 
34
                unset($this->a[$index]);
 
35
        }
 
36
}
 
37
 
 
38
$obj = new Object;
 
39
 
 
40
var_dump($obj[1]);
 
41
var_dump($obj[2]);
 
42
$obj[2]++;
 
43
var_dump($obj[2]);
 
44
 
 
45
?>
 
46
===DONE===
 
47
--EXPECTF--
 
48
object::offsetGet(1)
 
49
string(6) "fooBar"
 
50
object::offsetGet(2)
 
51
int(1)
 
52
object::offsetGet(2)
 
53
 
 
54
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_004.php on line %d