PHP OOP: Method Chaining

Posted by Isis on Stack Overflow See other posts from Stack Overflow or by Isis
Published on 2010-06-07T15:47:12Z Indexed on 2010/06/07 16:12 UTC
Read the original article Hit count: 259

Filed under:
|
|

I have the following code,

<?php
class Templater
{
    static $params = array();

    public static function assign($name, $value)
    {
        self::$params[] = array($name => $value);
    }

    public static function draw()
    {
        self::$params;
    }
}


 $test = Templater::assign('key', 'value');
 $test = Templater::draw();
 print_r($test);

How can I alter this script so I could use this?

$test = Templater::assign('key', 'value')->assign('key2', 'value2')->draw();
print_r($test);

© Stack Overflow or respective owner

Related posts about php

Related posts about oop