tags:

views:

261

answers:

1

So, my problem is as follows. This code works fine when I load the page via the web browser. But when I run the script from the command line like so: "php script.php" it bombs.

script.php is:

<?php
include_once('class.WebsiteScraper.php');
$ws = new WebsiteScraper();
$ws->test();
...
?>

class.WebsiteScraper.php is:

<?php
echo 'test';
class WebsiteScraper {
    public function test() {
        echo 'test2';
    }
}
?>

This returns the error:

PHP Fatal error: Call to undefined method WebsiteScraper::test() in ... on line 4

Only when called via the command line does this happen. Another thing to note, when I append an

error_log('hey there');

To script.php, it throws the error to the standard out, rather than in my error log. But when called from the web browser it puts it in the error log. Any ideas?

+1  A: 

Use the command line option --ini to check if the command line is loading the same configuration file as apache:

php --ini

You could also call phpinfo().

It seems likely your file isn't being included - probably due to include paths.

Edit:

Try adding

error_reporting(E_ALL);
Greg
That's it! I'm using MAMP and I edited my ini file for MAMP (used in conjunction with Apache). But the sys ini file is somewhere else.
Dustin Hoffman
Welp, hang on. I've checked both ini files and both are pathing correctly. But when calling the script from the command line "error_log" still doesn't work.
Dustin Hoffman
Also, the included files aren't returning errors - php is able to "open a stream", but none of the code in the files is being accounted for / executed.
Dustin Hoffman