簡體   English   中英

PHP類:if語句內的類內的調用函數

[英]PHP Class: Call function inside class inside if statement

class ValidatorClass{
    public function PersonAge($firstPar, $secondPar){
        if(!$this->isFloat($firstPar)){
            return 0;   
        }
        if(!$this->isNumber($secondPar)){
            return 0;   
        }/*the function contiues to a select query that works if I remove the two filters on top and returns 1 if match found(but it doesn't matter for the situation, just to clarify)*/
    }
    }//PersonAge()

    public function isFloat($inputFloat){
        return is_float($inputFloat);
    }
    public function isNumber($inputNumber){
        return is_int($inputNumber);
    }
    public function isString($inputString){
        return is_string($inputString);
    }
}

基本上,過濾器不起作用,它們返回0,函數停止,根據情況,值是float或integer。 它們應該返回true,並且不應該返回0,該函數應該繼續。 還有另一種方法可以做同樣的事情嗎? 或者,也許要使它起作用。

這是因為is_int檢查數字是否為INT而不是數字文本。
6-這對is_int有好處。
'6'-這對is_int不利,因為它不是字符串,而是int。

您應該使用is_numeric()來檢查字符串是否為數字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM