php command line print in object not returning
I am开发者_高级运维 trying to run some php from the command line but the php in my class is not being hit.
<?php
print "1";
try {
print ",2";
$a = new myClass("");
}
catch (Exception $e) {
print $e->getMessage();
}
print ",3";
myClass
<?php
class myClass{
function __construct($var) {
print "My Class";
}
}
The output I am getting is:
1,2
Process finished with exit code 255
Why is the print in the constructor not outputting to the command line?
you should be doing $a = new Checkout();
as that is the name of your class, even though you have it in a file named myclass.php probably. you should have gotten the following error:
1
PHP Fatal error: Class 'myClass' not found in somefile.php on line whateverlineitwas
PHP Stack trace:
,2
PHP 1. {main}() /Users/cdaley/Sites/PHP-1.php:0
You are not getting the 3 either because the code is failing and exiting, weird you are not seeing an error. PS, it throws a fatal error, not an exception, prolly why it did not CATCH it.
Here is the code i am running via command line:
<?php
class myClass {
function __construct($var) {
print "My Class";
}
}
print "1";
try {
print ",2";
$a = new myClass("");
}
catch (Exception $e) {
print $e->getMessage();
}
print ",3";
?>
You need to include the file
include `myClass.php';
The path may vary depending on your file structure.
Exist status 255 is a fatal error. You should try setting error_reporting
to E_ALL
error_reporting(E_ALL)
to ensure no errors are masked out. That should help you spot the culprit.
精彩评论