, sihirli yöntem __call çağrıyı müdahale edebilir, bu yüzden uygun gördüğüm gibi durumu ele verebilir: http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methodsphp'de global kapsam için sihirli yöntem __call() gibi bir işlev var mı? Bir çağrı bir sınıfta tanımlanmamış bir yönteme yapılırsa
sayede php sağlanan herhangi bir mekanizma var mı ben Aynı şeyi global kapsamdaki işlevlerle yapabilir. nokta iyi koduyla gösterilmektedir:
<?php
function return_some_array(){
$a = array();
//Do stuff to array
return array();
}
// Now i call the function like so:
$give_me_array = return_some_array();
// But sometimes I want the array to not contain zeroes, nulls etc.
// so I call:
$give_me_array_filtered = return_some_array_filtered();
// But i haven't defined return_some_array_filtered() anywhere.
// Instead I would like to do something like so:
function __magic_call($function_name_passed_automatically){
preg_match('/(.*)_filtered$/', $function_name_passed_automatically, $matches);
$function_name_that_i_defined_earlier_called_return_some_array = $matches[1];
if($matches){
$result = call_user_func($function_name_that_i_defined_earlier_called_return_some_array);
$filtered = array_filter($result);
return $filtered;
}
}
//So now, I could call return_some_other_array_filtered() and it would work provided I had defined return_some_other_array().
//Or even Donkey_filtered() would work, provided I had defined Donkey() somewhere.
?>
bu mümkün değil midir?
Teşekkürler! Bence deneyeceğim. –
@ V-A Bu, elbette bir şeyleri yapmak için oldukça gereksiz ve gereksiz bir şekilde aceleci bir yoldur. Fonksiyonlarınızı normal olarak tanımlamalı ve çağırmalısınız. – deceze
Başka bir notta: bunun bir uzantı olarak uygulanabileceğini düşünüyor musunuz? Oldukça basit olacağını düşünürdüm? –