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

search for in the

타입 저글링> <NULL
Last updated: Sun, 25 Nov 2007

view this page in

이 문서에서 사용되는 의사 타입

mixed

mixed는 인자가 여러 타입을 허용한다는 것을 가리킨다 (모든 변수형일 필요는 없다)

gettype()은 모든 PHP 타입을 다루고, 반면에 str_replace()은 문자열과 배열만을 다룬다.

number

number는 인자가 integerfloat일수 있음을 가리킨다.

callback

call_user_func()usort()와 같은 함수는 인자로 사용자선언 콜백 함수를 취급한다. 콜백 함수는 단순한 함수 뿐만 아니라 정적 클래스 메소드를 포함하는 객체 메소드가 될수 있다.

PHP 함수는 단순히 그 이름을 문자열로 전달한다. 다음 함수를 제외하고 내장 함수나 유저 선언 함수를 전달할수 있다. array(), echo(), empty(), eval(), exit(), isset(), list(), print(), unset().

인스턴스화된 객체의 메소드는 인덱스 0의 요소인 객체와 인덱스 1의 요소인 메소드명을 포함하는 배열로 전달된다.

정적 클래스 메소드는 인덱스 0의 요소인 객체 대신 클래스명을 전달함으로써 그 클래스의 객체를 인스턴스화하지 않고도 전달될수 있다.

Example#1 콜백 함수 예제코드

<?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'));


?>



타입 저글링> <NULL
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
이 문서에서 사용되는 의사 타입
Hayley Watson
23-May-2007 10:44
The mixed pseudotype is explained as meaning "multiple but not necessarily all" types, and the example of str_replace(mixed, mixed, mixed) is given where "mixed" means "string or array".
Keep in mind that this refers to the types of the function's arguments _after_ any type juggling.
levi at alliancesoftware dot com dot au
08-Feb-2007 02:44
Parent methods for callbacks should be called 'parent::method', so if you wish to call a non-static parent method via a callback, you should use a callback of
<?
 // always works
 $callback = array($this, 'parent::method')

 // works but gives an error in PHP5 with E_STRICT if the parent method is not static
 $callback array('parent', 'method');
?>
Edward
01-Feb-2007 02:15
To recap mr dot lilov at gmail dot com's comment: If you want to pass a function as an argument to another function, for example "array_map", do this:

regular functions:
<?
array_map(intval, $array)
?>

static functions in a class:
<?
array_map(array('MyClass', 'MyFunction'), $array)
?>

functions from an object:
<?
array_map(array($this, 'MyFunction'), $array)
?>

I hope this clarifies things a little bit

타입 저글링> <NULL
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites