Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created July 5, 2011 23:00
Show Gist options
  • Save yitsushi/1066157 to your computer and use it in GitHub Desktop.
Save yitsushi/1066157 to your computer and use it in GitHub Desktop.
How to extend the ArrayObject and create a custom array
<?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