<?
/*
 * Copyright (c) 2006 ArcStone Technologies, Inc. and Austin T. Smith
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

class Adder
{
    private function 
__construct() {}
    
    public 
$first$second;
    public function 
add()
    {
        
$overload = new Overloader(func_get_args());
        if(
$args $overload->match(array("first" => Overloader::ARG_FLOAT"second" => Overloader::ARG_FLOAT)))
        {
            return 
$args->first $args->second;
        }
        elseif(
$args $overload->match(array("first" => Overloader::ARG_STRING"second" => Overloader::ARG_STRING)))
        {
            return 
$args->first $args->second;
        }
        elseif(
$args $overload->match(array("first" => Overloader::ARG_ARRAY"second" => Overloader::ARG_ARRAY)))
        {
            return 
$args->first $args->second;
        }
        elseif(
$args $overload->match(array("first" => "Adder""second" => "Adder")))
        {
            return 
$this->add($args->first->add(), $args->second->add());
        }
        elseif(
$args $overload->match(array()))
        {
            return 
$this->add($this->first$this->second);
        }
        else
        {
            
$overload->error();
        }
    }
    
    public static function 
create($first=null$second=null)
    {
        
$adder = new Adder;
        
$adder->first $first;
        
$adder->second $second;
        return 
$adder
    }
}

echo 
Adder::create()->add(1.12.2) . "\n";

echo 
Adder::create()->add("austin"" smith") . "\n";

print_r(Adder::create()->add(array(=> "austin"), array(=> "smith")));

try
{
    echo 
Adder::create()->add("austin"1) . "\n";

catch(
Exception $e)
{
    echo 
"bad programmer!\n";
}

echo 
Adder::create(1.4,-1.4)->add() . "\n";

echo 
Adder::create(
        
Adder::create(
             
Adder::create(0.6,3.667),
             
Adder::create(304.892,394.2)
         ),
         
Adder::create(
             
Adder::create(0.568,452.14),
             
Adder::create(
                 
Adder::create(4.3,349.12),
                 
Adder::create(4.4,5.5)
            )
        )
     )->
add() . "\n";
?>