PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
toasty2
Forum Contributor
Posts: 361 Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA
Post
by toasty2 » Tue Jul 03, 2007 10:56 am
I'm wanting to provide my own error message if something fails to include/require.
PHP yells at me if I try something like this:
Code: Select all
include 'file.php' or die('error message');
toasty2
Forum Contributor
Posts: 361 Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA
Post
by toasty2 » Tue Jul 03, 2007 1:25 pm
Ah, a nice time to use the ternary operator
Code: Select all
file_exists('file.php') ? require 'file.php' : die('Error Message');
mabufo
Forum Commoner
Posts: 81 Joined: Thu Jul 10, 2003 11:11 pm
Location: Orland Park, IL
Contact:
Post
by mabufo » Tue Jul 03, 2007 2:19 pm
toasty2 wrote: Ah, a nice time to use the ternary operator
Code: Select all
file_exists('file.php') ? require 'file.php' : die('Error Message');
I always want to use that, but somehow never end up doing it. Good for you!
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Tue Jul 03, 2007 3:37 pm
Note that file_exists() won't search your include path. You might be better off overloading your error reporter.
toasty2
Forum Contributor
Posts: 361 Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA
Post
by toasty2 » Tue Jul 03, 2007 5:19 pm
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Tue Jul 03, 2007 5:21 pm
Yes, but that kind of defeats the purpose of an include path, which is to allow multiple paths to have include files.
toasty2
Forum Contributor
Posts: 361 Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA
Post
by toasty2 » Tue Jul 03, 2007 5:27 pm
Alright, then:
Code: Select all
set_include_path(get_include_path().PATH_SEPARATOR.'/');
Better?
msimoes
Forum Newbie
Posts: 5 Joined: Tue Jul 03, 2007 8:24 am
Post
by msimoes » Tue Jul 03, 2007 8:11 pm
If your using PHP5, you can always make it a little more "easier" by implemeting
exceptions to the application.
Best regards,
Miguel Simões