note 111175 added to class.arrayaccess

From: Date: Tue, 22 Jan 2013 18:34:31 +0000
Subject: note 111175 added to class.arrayaccess
Groups: php.notes 
Request: Send a blank email to php-notes+get-193347@lists.php.net to get a copy of this message
The reason of the following implementation is that i want to avoid warnings if an array element is not set. The constructor gets a variable named $useIfValueNotSet which is the default that will be used when an element is not set. I did not extend other parts, only the part related to the stuff above. Code (extends code from http://de1.php.net/manual/en/class.arrayaccess.php#97163): class MyArray implements arrayaccess { /** * */ protected $_useIfValueNotSet = ''; /** * Constructor */ public function __construct($useIfValueNotSet = '') { $this->_useIfValueNotSet = $useIfValueNotSet; } public function set($name, $value) { $this->{$name} = $value; } /** * Uses a default if element is not set */ public function get($name) { return true === isset($this->{$name}) ? $this->{$name} : $this->_useIfValueNotSet; } public function offsetGet($offset) { return $this->get($offset); } public function offsetSet($offset, $value) { $this->set($offset, $value); } public function offsetExists($offset) { return isset($this->{$offset}); } public function offsetUnset($offset) { unset($this->{$offset}); } } ---- Server IP: 69.147.83.199 Probable Submitter: 178.24.210.71 ---- Manual Page -- http://php.net/manual/en/class.arrayaccess.php Edit -- https://master.php.net/note/edit/111175 Del: integrated -- https://master.php.net/note/delete/111175/integrated Del: useless -- https://master.php.net/note/delete/111175/useless Del: bad code -- https://master.php.net/note/delete/111175/bad+code Del: spam -- https://master.php.net/note/delete/111175/spam Del: non-english -- https://master.php.net/note/delete/111175/non-english Del: in docs -- https://master.php.net/note/delete/111175/in+docs Del: other reasons-- https://master.php.net/note/delete/111175 Reject -- https://master.php.net/note/reject/111175 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193347) next »