From: "Vivian Steller" <[EMAIL PROTECTED]>

> Vivian Steller wrote:
>
> > Hello,
> >
> > as you know there is a new callback function __call($method, $params) in
> > php5. the __call() method of an object is called, if the method named
> > $method is not declared in this class.
> >
> > i want this function simply call the method of another class with
> > "SomeClass::$method(...)" but i'm getting into trouble (bit heavy
> > programming!:) passing the arguments (stored as Array in $params) to the
> > "SomeClass::$method([arguments])" method...
> > further, i think i'm getting problems with objects passed through the
> > __call() method?!
> >
> > any suggestions?
> > thanks
> >
> > vivi
>
> ok, here is an example: hope you'll understand what i want...
>
> <pre>
> <?php
>         class MyClass {
>                 function __call($method, $params) {
>                         // $params = Array(mixed var, mixed var, ...);
>                         print("request for " . $method . "()\n");
>
>                         // how to get objects in this string?!
>                         // do i have to implement "switch($type) { case
"object": ... }" here?!
>                         $parameterstring = "\"" . $params[0] . "\"";
>                         eval("OtherClass::" . $method . "(" .
$parameterstring . ");");

Can't you just say:

OtherClass::$method($params);

here?

>
>                 }
>         }
>
>         class OtherClass {
>                 function OtherMethod($obj = false) {
>                         if(is_object($obj)) {
>                                 // this method receives an object to show
the difficulties with object
> passed through call...
>                                 if(method_exists($obj, "printSomething"))
{
>                                         $obj->printSomething();
>                                 }
>                         }
>                         else {
>                                 print("Error: no object passed! '" . $obj
. "'\n");
>                         }
>                 }
>         }
>
>         class Whatever {
>                 function printSomething() {
>                         print("passing object through __call() is
fine\n");
>                 }
>         }
>
>         $someObj = new Whatever();
>         // $someObj->printSomething();
>
>         $MyObj = new MyClass();
>         // this works perfectly
>         $MyObj->OtherMethod("passing a string");
>         // this is my problem...
>         $MyObj->OtherMethod($someObj);
> ?>
> </pre>

---John Holmes...

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

Reply via email to