<?xml version="1.0"?>
<slide title="Intercepci&#243;n de llamadas a m&#233;todos">
<blurb>
Cuando un m&#233;todo no esta explicitamente declarado para un objeto,
PHP 5 puede pasar la ejecuci&#243;n a un m&#233;todo especial llamado %__call()%.
</blurb>
<example type="php" result="0"><![CDATA[<?php
    class Delegador {
        private gato;
        private perro;
        
        function __construct() {
            $this->gato = new Gato();
            $this->perro = new Perro()
        }
        
        function __call($methodName, $args) {
            if ($methodName == 'maulla') {
                return $this->gato->maulla($args);
            } else (
                return $this->perro->$methodName($args);
            }
        }
    }
    
    $obj = new Delegador();
    echo $obj->ladra('fuerte');  // usa al perro
    echo $obj->maulla('suave');  // usa al gato
    echo $obj->muerde(); // el perro de nuevo
?>]]>
</example>
</slide>

