Çalışması gerektiği gibi, bu, oldukça garip; Bu kod kısmını test ettikten sonra:
class ClassA {
public static function a($param) {
var_dump($param);
}
}
ClassA::a(123);
Ben bu çıktıyı alıyorum:
int 123
Statik yöntem gerçekten parametre almak yoktu (ve aslında, neden olmasın hiçbir sebep göremiyorum) gösterir.
As a sidenote, you are ending with this portion of code :
die(0);
exit (which is the same as die) * (vurgu benim) için kılavuz sayfasını alıntı *:
void exit ([ string $status ] )
void exit ( int $status )
If status is a string, this function
prints the status just before exiting.
If status is an integer, that
value will also be used as the exit
status.
[...]
Note: PHP
>= 4.2.0 does NOT print the status if it is an integer.
Sen 4.2 daha yeni bir sürümü PHP 5.3 kullanıyorsanız; ve senin durumunda, $status tamsayı strong> - bu yayınlanmıştır kodu ile görüntülenen bir şey yok gayet normal olduğu anlamına gelir.
And, to finish : if you remove the die, your code ends up doing this :
if(!filter_var($index, FILTER_VALIDATE_INT)) {
throw new Exception('...');
}
$index = 0 ile
filter_var returns the filtered value ; using FILTER_VALIDATE_INT, ben bir tamsayı almak için filtreleme varsayalım - ve 0 tam sayıdır.
filter_var 0 dönecektir için çağrı anlamına gelir.
0 false (see Converting to boolean) -- so, you will enter into the if blok olarak kabul edilir; ve istisna atılır.
Considering filter_var returns :
- Filtrelenen veriler,
- veya
false filtre başarısız olduğunda,
- Ve bu
0, iade edilebilir geçerli bir veri
Muhtemelen === operatörü (see Comparison Operators) , to compare the returned value to false kullanmalıdır. Hangi böyle olmazdı bazı kod anlamına gelir:
if(filter_var($index, FILTER_VALIDATE_INT) === false) {
throw new Exception('...');
}
Hope this helps !