Newbie question: require_once() is not working

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

Post Reply
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

Newbie question: require_once() is not working

Post by victorsk »

Hello,

I have a very strange problem. The require_once() function doesn't seem to be working, it works fine on my other servers, but not on another.

I've deployed all the packages like SOAP/pear, restarted Apache, but I just get a blank screen when trying to use require_once(). I even researched for error-handling but I still get a blank page, with no error messages at all, nothing, here's my code, hope somebody could help me with this one:

Code: Select all

<?php
/*
       this file is for getting data using SOAP requests
*/
try
{

require_once('SOAP/Client.php');// or die ("problems");
}

catch Exception ($e)
{
        echo $e->getMessage();
        //also tried $e->getMessage();
}
everything is just blank. When I try to get the actual printout of SOAP response, the page gets blank too. It also gets blank when I try to directly access Client.php file, but I get an error on another server (as it should) where require_once() is working.

Please help,
Thank you,
Victor.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

require_once doesn't throw an exception, so you need to remove the try/catch block as it won't fire.

Also, you should turn on all errors and warnings. I think this is probably giving you a fatal error, but since error reporting is off that is your problem. I don't remember the syntax you need to turn on the errors in code, but someone else here should be able to help with that, or you can google for "php error reporting".
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your catch statement would generate a parse error, I believe. I can only assume you've removed a large amount of code for the example. Something tells me that code is important.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try/Catch would look like this:

Code: Select all

<?php
try {
  // Something that could throw an exception
} catch (Exception $e) {
  echo $e->getMessage();
}
?>
However, require_once results in a fatal error if the file to include is not found, so you really should not try to use it in a try/catch block. Just call it.

Code: Select all

<?php
require_once 'SOAP/Client.php';
?>
Post Reply