|
|||||||
|
PHP Error Handling
I'm writing a program in php and I'm currently testing a class I wrote. Part of testing this class involved calling a method while passing an incorrect quantity of arguments. For its part, PHP throws a Warning (Missing Argument), but continues running the method with null in place of the missing argument. This can be problematic down the line.Calling a method or function with an incorrect quantity of arguments would halt a program compiled in Java or C++ (probably wouldn't compile). I'm not sure why PHP should be any different. As such, I'd like to know where/how I configure PHP to completely halt on warnings. I'd like to do this globally on my own, personal server, but I'm wondering if this is something I can configure ad hoc as well (should I distribute a program to another server that doesn't have such settings globally). Thanks in advance. |
| 02-19-2013, 07:11 AM | |
|
|
|
You may want to read on Scripting Languages Vs Programming Languages
php is scripting language and interpreted at run time not compiled. Programming Language (Java of C++)is typically first compiled to a native machine code or to an intermediate language |
|
PHP's configuration allows for several behaviors to be changed, including error display and error checking. I was hoping that someone would be able to lead me directly to what I need rather than having to dig around a bunch of crap. Note: http://stackoverflow.com/question...ce-warning Example of what happened. I tested a function to add an entry into a database. It worked correctly when both arguments were passed. I tested the function when only one argument was passed. It tossed a warning, but still ran the function with the second argument replaced with null. This behavior is unacceptable and has the potential to completely fux a database. |
||
|
|
|
|
|
|
|
PHP Code:
PHP Code:
PHP Code:
This is bad. No amount of error detection prior to calling the method is going to solve this issue. Using try for every single function will also bloat the code to excessive levels. What should happen if addUser($x) is called is the program halts. Any other language would either halt or fail to compile if you have mismatched passed variables. JavaScript even halts on errors (another scripting language). Last edited by kakomu; 02-19-2013 at 01:47 PM.. |
||
|
Classic ASP halted on errors too, unless you told it to behave otherwise.
http://stackoverflow.com/question...ce-warning ? |
|
Last edited by menace33; 02-19-2013 at 02:31 PM.. |
|
|
Any input supplied to your application should be treated as untrusted and passed through a validation routine to ensure that the data is the proper type and format required by your application |
|
|
PHP Code:
Slickdeals Mobile Apps
iPhone App - Android App - iPad App (coming soon) Have an issue or suggestion with our mobile app? Send me a PM or Ask in our Issue & Suggestions Forum. |
|
|
I'm looking for information to get PHP to function like any other compiler out there. If you aren't responding to this request, please refrain from responding. Last edited by kakomu; 02-19-2013 at 02:52 PM.. |
||
|
PHP is not a compiler and cannot be forced to malfunction in the way that compilers do. What you are trying to do is not possible, sorry.
Try this: PHP Code:
Last edited by WarrenM; 02-19-2013 at 03:07 PM.. Speed does not kill. In fact speed never killed anyone. Suddenly becoming stationary that's what gets you. - Jeremy Clarkson, Top Gear S06E10
Intel i7 950 @ 4ghz | Corsair H80 | Gigabyte GA-X58-USB3 mobo | 18GB DDR3-1333 RAM | 4 x 2TB HD | Sapphire Radeon HD5770 w/3 monitors | Triple boot Lion/Win7/Fedora |
|
|
|
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Xbox Errors | zazon | Tech Support | 9 | 01-30-2013 11:22 AM |
| Error messages after IE8 security update | ronm | Tech Support | 7 | 01-20-2013 04:26 PM |
| "No Sim" Error on my Iphone 4s | xNico | Tech Support | 3 | 01-18-2013 04:14 PM |
| Curious as to why one computer on my network occasionally gets a "Limited Access" error when trying to connect to the wireless network? | GBAstar | Tech Support | 27 | 01-09-2013 09:28 AM |
| Error 0xc00000e9 on Clean Windows 7 install on new build | helloha1 | Tech Support | 18 | 01-02-2013 03:37 PM |