In some PHP built-in functions (such as mkdir), add @ to the front to block the errors thrown by the function. how can we implement the UDF? I tried thrownewException and trigger_error cannot be blocked by @. note: Yes, for example, I want to write a... built-in PHP function (for example
mkdir
), Add @ to the front to block the errors thrown by the function.
So how do custom functions implement this?
I tried it.throw new Exception
Andtrigger_error
Cannot be@Shield
Note:
Yes, for example, I want to writeJsonFile::get()
METHOD. if the object does not exist, an error is thrown, the path is invalid, the decoding fails, and an error is returned.False
You can capture and process the error information. if you do not care about the error information, you can only obtain the file content or false (failure ).
@JsonFile::get()
This call
This is mainly for convenience. How can I implement such a custom method (or function?
Or do I have a bad idea? Is there a convenient and reasonable implementation method?
Reply content:
In some PHP built-in functions (suchmkdir
), Add @ to the front to block the errors thrown by the function.
So how do custom functions implement this?
I tried it.throw new Exception
Andtrigger_error
Cannot be@Shield
Note:
Yes, for example, I want to writeJsonFile::get()
METHOD. if the object does not exist, an error is thrown, the path is invalid, the decoding fails, and an error is returned.False
You can capture and process the error information. if you do not care about the error information, you can only obtain the file content or false (failure ).
@JsonFile::get()
This call
This is mainly for convenience. How can I implement such a custom method (or function?
Or do I have a bad idea? Is there a convenient and reasonable implementation method?
First, make sure that the syntax is correct. then it seems that it has nothing to do with throw new Exception and trigger_error. the code is as follows:
Warning: mysql_connect () [function. mysql-connect]: Access denied for user 'username error '@ 'localhost' (using password: YES) in D: Projectsns1.php on line 4
Test2 does not throw a Warning.