[ create a new paste ] login | about

Link: http://codepad.org/VDAaikF2    [ raw code | output | fork ]

PHP, pasted on Apr 9:
<?php

    class SimpleArrayObject
    {
        public function __construct($array = null)
        {
            foreach ((array) $array as $key => $value) {
                $this->{$key} = $value;
            }
        }

        public function __set($key, $value)
        {
            $this->{(string) $key} = $value;
        }
    }

    function object($value)
    {
        if (is_object($value)) {
            return $value;
        }

        if (!is_array($value)) {
            $value = array('scalar' => $value);
        }

        return new SimpleArrayObject($value);
    }

    $obj = object(array(1,2,3));
    $obj->{1} = "Duplicate key 1";
    $obj->{2} = "Duplicate key 2";
    $obj->{3} = "Duplicate key 3";
    $array = (array)$obj ;
    print_r($array);


Output:
1
2
3
4
5
6
7
Array
(
    [0] => 1
    [1] => Duplicate key 1
    [2] => Duplicate key 2
    [3] => Duplicate key 3
)


Create a new paste based on this one


Comments: