hobodave (owner)

Revisions

gist: 224818 Download_button fork
public
Public Clone URL: git://gist.github.com/224818.git
Embed All Files: show embed
foo.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
 
class Base
{
    protected $_availableSizes = array();
 
    public function __call($name, $args)
    {
        $action = strtolower(substr($name, 0, 3));
        $field = '_' . strtolower($name[3]) . substr($name, 4);
 
        switch ($action) {
            case 'set':
                $this->$field = $args[0];
                break;
 
            case 'get':
                return $this->$field;
                break;
 
            default:
                break;
        }
    }
}
 
class Foo extends Base
{
    /**
* Overrides the admin setAvailableSizes to ensure every
* item within the context of an Order has a size and cost.
*
* @return void
**/
    public function setAvailableSizes(array $sizes)
    {
        parent::setAvailableSizes($sizes);
        if (empty($this->_availableSizes)) {
            $this->_availableSizes[] = array(
                'name' => 'Default',
                'cost' => 0.00,
            );
        }
    }
}
 
$foo = new Foo();
$foo->setAvailableSizes(array(
    array(
        'name' => 'Test',
        'cost' => '0.00',
    ),
));
 
var_dump($foo);
 
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 5.2.9 output
 
object(Foo)#1 (2) {
  ["_availableSizes:protected"]=>
  array(1) {
    [0]=>
    array(2) {
      ["name"]=>
      string(7) "Default"
      ["cost"]=>
      float(0)
    }
  }
  ["_availablesizes"]=>
  array(1) {
    [0]=>
    array(2) {
      ["name"]=>
      string(4) "Test"
      ["cost"]=>
      string(4) "0.00"
    }
  }
}
 
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
5.2.10+ output
 
object(Foo)#1 (1) {
  ["_availableSizes:protected"]=>
  array(1) {
    [0]=>
    array(2) {
      ["name"]=>
      string(4) "Test"
      ["cost"]=>
      string(4) "0.00"
    }
  }
}