PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

class_exists> <call_user_method_array
Last updated: Fri, 11 Apr 2008

view this page in

call_user_method

(PHP 4, PHP 5)

call_user_method — Chiama un metodo dell'oggetto indicato [deprecated]

Descrizione

mixed call_user_method ( string $nome_metodo , object &$obj [, mixed $parametro [, mixed $... ]] )
Avviso

A partire dalla versione 4.1.0 l'uso della funzione call_user_method() è sconsigliato; in sostituzione utilizzare la serie call_user_func() con la sintassi array(&$obj, "method_name").

Richiama il metodo indicato da nome_metodo dell'oggetto oggetto . Di seguito si fornisce un esempio di utilizzo. Qui si definisce una classe, si istanzia un oggetto, e si utilizza call_user_method() per richiamare il metodo stampa_info

<?php
class Stato {
    var 
$NOME;
    var 
$TLD;
    
    function 
Stato($nome$tld
    {
        
$this->NOME $nome;
        
$this->TLD $tld;
    }

    function 
stampa_info($prestr "") {
        echo 
$prestr "Stato: " $this->NOME "\n";
        echo 
$prestr "Dominio di primo livello: " $this->TLD "\n";
    }
}

$paese = new Stato("Peru""pe");

echo 
"* Richiamo il metodo direttamente\n";
$paese->stampa_info();

echo 
"\n* utilizzo dello stesso metodo in modo indiretto\n";
call_user_method("stampa_info"$paese"\t");
?>

Vedere anche call_user_func_array() e call_user_func().



class_exists> <call_user_method_array
Last updated: Fri, 11 Apr 2008
 
add a note add a note User Contributed Notes
call_user_method
ravichandran_11 at yahoo dot co dot in
10-Mar-2008 05:32
<?php
class abc{
   function
func($argument)  {
      
$argument="It works";
   }
}
$obj=new abc;
$argument_to_be_changed="No it doesn't work";
call_user_method("func", $obj, &$argument_to_be_changed);
echo
"Result : ".$argument_to_be_changed;
?>

This code is working. But will through some warning message which you can hide by configuring php.ini
j dot h at h-elektro dot de
05-Feb-2007 12:11
It does not work to use Pointers as Arguments:

<?php
class abc{
   function
func(&$argument)  {
      
$argument="It works";
   }
}

$obj=new abc;
$argument_to_be_changed="No it doesnt";
call_user_method("func", $obj, $argument_to_be_changed);

echo
"Result".$argument_to_be_changed;
?>

The result is: "No it doesnt".

Regards
der Jan
paulo at emd dot com dot br
18-Sep-2000 05:12
This function is very similar to this:

$method="Print";
$object->$method($param1,$param2);

Note the extra $ after the ->
jmcastagnetto at php dot net
21-Aug-2000 05:04
You can pass a variable number of parameters to a function, use a definition like:

function mymethod ($v1, $v2, $v3="", $v4="")

and then you can pass 2, 3 or 4 parameters. This is explained in the "Functions" section of the manual.

See also the PHP4 functions: func_num_args(), func_get_arg(), and func_get_args(), and examples therein

class_exists> <call_user_method_array
Last updated: Fri, 11 Apr 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites