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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.