473,382 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Handling include() warnings

I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.
Jul 17 '05 #1
7 2219
if (!include('Foo.php')) {
print "ERROR";
}

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.

Jul 17 '05 #2
if (!include('Foo.php')) {
print "ERROR";
}

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.

Jul 17 '05 #3
if (!include('Foo.php')) {
print "ERROR";
}

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.

Jul 17 '05 #4
oops sorry for sending the same message three times. twas a misake...

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.

Jul 17 '05 #5
you might want to suppress the error generated by the failed include... and
maybe display some useful info... or maybe not.

if (!@include('Foo.php')) {
exit('Error in file: ' . __FILE__ . ' on line: ' . __LINE__);
}

- Rook.

"kingofkolt" <je**********@comcast.net> wrote in message
news:cXIvc.3120$%F2.940@attbi_s04...
if (!include('Foo.php')) {
print "ERROR";
}

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.


Jul 17 '05 #6
you might want to suppress the error generated by the failed include... and
maybe display some useful info... or maybe not.

if (!@include('Foo.php')) {
exit('Error in file: ' . __FILE__ . ' on line: ' . __LINE__);
}

- Rook.

"kingofkolt" <je**********@comcast.net> wrote in message
news:cXIvc.3120$%F2.940@attbi_s04...
if (!include('Foo.php')) {
print "ERROR";
}

"Pete Forman" <pe*********@westerngeco.com> wrote in message
news:7j**********@wgmail2.gatwick.eur.slb.com...
I'm new to PHP and trying to get a handle on some basics.

require() and include() both load up a file. require() exits if the
inclusion fails while include() issues a warning and the script
continues. In the latter situation how should I detect the failure?

include('Foo.php');

if (...) {
Foo::do_something();
} else {
backup_action();
}

What should the test be? Can I catch the warning thrown by the
include()? Should I search through get_included_files()? The
file being included is a "standard" one which might be missing from an
installation, so I can't edit it to define a constant in it.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.



Jul 17 '05 #7
Thanks for all the replies, even if they were from only 2 people ;-)

My requirement is to to use a module if it is available, otherwise
work round it. So using @ to suppress warnings is appropriate.

$foo_available = @include('Foo.php');

if ($foo_available) {
Foo::do_something();
} else {
backup_action();
}

--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pe*********@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
1
by: Marco Spatz | last post by:
Hi, I used PCLint to check my code yesterday and got some warnings about "Repeated include files" and "Redundant declaration for symbol 'CLASSNAME'". I know the reasons for these warnings and I...
1
by: Vivek | last post by:
Hi, This is a very general problem which iam sure application programmers all over have faced. How does one handle the warnings that DB2 issues ? Should they be ignored or treated the same as...
12
by: Stephan Kuhagen | last post by:
Hello Please forgive me, if this is the wrong NG, since this is a compiler specific C++-Question: I'm managing a huge build system for multiple platforms (Win*, Linux, MacOSX). Most of our...
2
by: Sergei Shelukhin | last post by:
Hi. I need to handle warnings in incorrect regular expressions executed using preg_match. Warnings shouldn't appear, instead I want to output some generic message like: "Bad regex: $regex" and...
0
by: Xavier Serrand | last post by:
On my systme, include <stdio.hand <stdlib.h raise many warnings (not C99 conformant...). I don't want to take care of those warnings because release will be built on an other system ... Does...
16
by: john6630 | last post by:
Coming from the .Net world, I am used to the try...catch...finally approach to error handling. And PHP 5 now supports this approach. But I am not clear what happens to unhandled errors/exceptioins?...
5
by: kellygreer1 | last post by:
I think I'm not quite understanding something about error handling in PHP5. I have written some PHP code to index the contents of C drive on a Windows machine. When it gets to certain special...
5
by: Conrad Lender | last post by:
I'd like to hear your opinions about the appropriate way to deal with non-critical errors that can occur in user-defined functions. For example, an application chooses to extend String.prototype...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.