Re: PHP Brain Teasers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
> On Wed, 2007-06-27 at 00:24 +0100, Colin Guthrie wrote:
>> Daniel Brown wrote:
>>>    What the hell?  Why not start a thread that can be fun and
>>> challenging for all of us.  It's something I haven't seen done
>> Here's another quickie: Dead simple one!
>>
>> <?php
>>
>> function x($x)
>> {
>>   switch ($x)
>>   {
>>     case 1: return 'bitten';
>>     case 2: return 'shy';
>>   }
>> }
> 
> Hmmm... would be better as (:
> 
> <?php
> 
> function x( $x )
> {
>     echo 'bitten';
>     echo 'shy';
>     echo 'shy';
> }
> 
> ?>


I guess you could call that different syntax, same semantics!

> Here's another one:
> 
> <?php
> 
>     class money
>     {
>         var $pennies = 0;
> 
>         function money( $amount=0 )
>         {
>             $this->pennies = $amount;
>         }
> 
>         function save()
>         {
>             return true;
>         }
>     }
> 
>     class account
>     {
>         var $total = 0;
> 
>         function account( $init=0 )
>         {
>             $this->total = $init;
>         }
> 
>         function add( $money )
>         {
>             $this->total += $money->pennies;
>         }
>     }
> 
>     $earned = new account();
>     $penny  = new money( 1 );
> 
>     if( $penny->save() )
>     {
>         $earned->add( $penny );
>     }
> 
> ?>

Nice :p

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux