I define a function that accepts the String parameter, but transmits a null value during the call. php will report a fatalerror, but the actual situation will indeed result in a null parameter, I want to define a function that specifies the parameter type and can accept null. what should I do? {Code ...} execute... I define a function that accepts the String parameter, but transmits a null value during the call. php will report a fatal error, but the actual situation will indeed result in a null parameter, I want to define a function that specifies the parameter type and can accept null. what should I do?
Run the following command:
>php t.phpCatchable fatal error: Argument 1 passed to foo() must be an instance of String, null given, called in /Users/jiajun/t.php on line 7 and defined in /Users/jiajun/t.php on line 3
Reply content:I define a function that accepts the String parameter, but transmits a null value during the call. php will report a fatal error, but the actual situation will indeed result in a null parameter, I want to define a function that specifies the parameter type and can accept null. what should I do?
Run the following command:
>php t.phpCatchable fatal error: Argument 1 passed to foo() must be an instance of String, null given, called in /Users/jiajun/t.php on line 7 and defined in /Users/jiajun/t.php on line 3
If you do not provide a parameter, the default value is null.
Remove the String modifier.
To determine the parameter type, use is_string ($ arg.
Http://www.php.net/manual/en/language...
If NULL is used as the default parameter value, it will be allowed as an argument for any later call
The manual has already been quite clear.