Comunitatea PHP Romania
 

 
Pseudo-types used in this documentation

Pseudo-types used in this documentation

mixed

mixed indicates that a parameter may accept multiple (but not necessarily all) types.

gettype() for example will accept all PHP types, while str_replace() will accept strings and arrays.

number

number indicates that a parameter can be either integer or float.

callback

Some functions like call_user_func() or usort() accept user defined callback functions as a parameter. Callback functions can not only be simple functions but also object methods including static class methods.

A PHP function is simply passed by its name as a string. You can pass any builtin or user defined function with the exception of array(), echo(), empty(), eval(), exit(), isset(), list(), print() and unset().

A method of an instantiated object is passed as an array containing an object as the element with index 0 and a method name as the element with index 1.

Static class methods can also be passed without instantiating an object of that class by passing the class name instead of an object as the element with index 0.

Exemplu 6-11. Callback function examples

<?php

// simple callback example
function my_callback_function() {
    echo
'hello world!';
}
call_user_func('my_callback_function');

// method callback examples
class MyClass {
    function
myCallbackMethod() {
        echo
'Hello World!';
    }
}

// static class method call without instantiating an object
call_user_func(array('MyClass', 'myCallbackMethod'));

// object method call
$obj = new MyClass();
call_user_func(array(&$obj, 'myCallbackMethod'));
?>

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
acasa , in pat
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Secured Loans | Mortgages | Loan | Car Finance | Credit Cards
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis