ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Does anyone know how I can make a php script ignore an error?
I have a script that returns values from an xml file. If one of the tags doesn't exist the script fails halfway through and prints an error to the screen. I would like it just to keep going and ignore the error.
I'm using php 4 so I can't use try-catch blocks, as far as I know they are only in php5.
It depends upon the type of errors that you are getting but it sounds as if you want to use the error_reporting() function to determine which errors you want to report.
A second approach is the use of the prefix operator @ which stops the reporting of errors (although I personally feel that using @ is a bad habit, it does have its uses)
error_reporting(0) does indeed suppress the error but the program execution fails at that point.
Here is my code, I have an array of items <Item></Item> in my xml file, must of them have a tag <ItemModel></ItemModel> but some of them don't. So when I try and get the value of the ITemModel tag for items that don't have an ItemModel I get the following error.
Code:
Fatal error: Call to a member function on a non-object in Test.php on line 90
Okay well you need to determine if $test[] really is an object before you try and dereference it. Add a conditional statement after the line that assigns $test to see if it has been set up correctly. If there are no tags then you want get_elements_by_tagname() to return an empty array and then you can look at the size of the array (if it is > 0) then continue with the next line of code:
PHP Code:
foreach($responseDoc->get_elements_by_tagname('Item') as $item) { $test = $item->get_elements_by_tagname('ItemModel'); if (count($test) > 0) $ItemModel = $test[0]->get_content(); }
You can also look at the is_a() or the more generic is_object() functions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.