note 110827 added to class.arrayaccess

From: Date: Wed, 12 Dec 2012 13:08:12 +0000
Subject: note 110827 added to class.arrayaccess
Groups: php.notes 
Request: Send a blank email to php-notes+get-192487@lists.php.net to get a copy of this message
Conclusion: Type hints \ArrayAccess and array are not compatible. <?php 2 3 class MyArrayAccess implements \ArrayAccess 4 { 5 public function offsetExists($offset) 6 { 7 8 } 9 10 public function offsetSet($offset, $value) 11 { 12 13 } 14 15 public function offsetGet($offset) 16 { 17 18 } 19 20 public function offsetUnset($offset) 21 { 22 23 } 24 } 25 26 27 function test(array $arr) 28 { 29 } 30 31 function test2(\ArrayAccess $arr) 32 { 33 34 } 35 36 37 $arrObj = new MyArrayAccess(); 38 test([]); //result: works! 39 test($arrObj); //result: does NOT work 40 test2([]); //result: does NOT work 41 test2($arrObj); // result: works! 42 ---- Server IP: 69.147.83.199 Probable Submitter: 72.52.91.2 (proxied: 77.222.73.150) ---- Manual Page -- http://php.net/manual/en/class.arrayaccess.php Edit -- https://master.php.net/note/edit/110827 Del: integrated -- https://master.php.net/note/delete/110827/integrated Del: useless -- https://master.php.net/note/delete/110827/useless Del: bad code -- https://master.php.net/note/delete/110827/bad+code Del: spam -- https://master.php.net/note/delete/110827/spam Del: non-english -- https://master.php.net/note/delete/110827/non-english Del: in docs -- https://master.php.net/note/delete/110827/in+docs Del: other reasons-- https://master.php.net/note/delete/110827 Reject -- https://master.php.net/note/reject/110827 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192487) next »