Le Lundi 21 Octobre 2002 18:14, NTPT a écrit :

> so it have a lot of  glue  code, that do  nothing but only glue together
> twoo parts of the program .
> if you write a  big application, with a lot of queries and function calls,
> a lot of the glue code is nedded, that need to be executed, look ugly and
> decrease readability of the program. And this is exactly the situation, I
> wnat avoid  by my suggestion.

Sounds correct, but there already have a very nice solution. Say you pass your 
data array and a second array or string this way:

function &stuff( $dataarray, $controlmixed )
{
        $res = FALSE ;
        // general stuff  with data
        sayblah() ;
        if ( is_array( $controlmixed ) {
                $class = $controlmixed[0] ;
                $method = $controlmixed[1] ;
                if ( is_object( $class ) {
                        // active instance call
                        $res = $class->$method( &$dataarry ) ;
                } else {
                        // static method call
                        $res = $class::$method( &$dataarray ) ;
                }
        } else {
                if_isstring( $controlmixed && function_exists( $controlmixed ) ){
                        // public function call
                        $res = $controlmixed( &$dataarray ) ;
                } else {
                        // maybe an eval string
                        // verify syntax for your needs
                        $evstr = "$controlmixed( &\$dataarray );" ;
                        eval( $evstr ) ;
                }
        }
        return $res ;
}

This way, you get a very powerful callback mechanism.

> Right. There is a little variables, that need to be truly GLOBALS.   GPRFS
> and db connection id  for example.

For db connection id, it's not a really good idea as (even if this is not the 
common case) one can need many active connections, ie when dealing in ncurses 
or gtk apps with huge data connections (I have an app with up to 12 diffrent 
connections on heterohenous databases).

> my suggestion is not mentioned to be a newbie helper. It is intended  for
> avoiding need of glue code(like in example aobve )and/or  redundant code,
> that can not be insert inside procedures because current var scope model.

Do you think the above could help ?

DJ Anubis


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to