Created
July 5, 2011 23:00
-
-
Save yitsushi/1066157 to your computer and use it in GitHub Desktop.
How to extend the ArrayObject and create a custom array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyArray extends ArrayObject { | |
function __construct($array = array()){ | |
parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); | |
} | |
public function get_property_string($sep = ':') { | |
return implode($sep, $this->getArrayCopy()); | |
} | |
public function __ToString() { | |
return 'Array'; | |
} | |
} | |
$a = new MyArray; | |
$a->append('LOGIN'); | |
$a->append('BETA_ACCESS'); | |
$a->append('COMMENT_WRITE'); | |
var_dump($a->get_property_string()); | |
/* | |
* Output: | |
* string(31) "LOGIN:BETA_ACCESS:COMMENT_WRITE" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment