我试图从命令行运行一些php,但我的类中的php没有被击中。
<?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";
}
}
我得到的输出是:
1,2
Process finished with exit code 255
为什么构造函数中的打印没有输出到命令行?
您应该执行$a = new Checkout();
,因为这是您的类的名称,即使您可能在名为myclass.php的文件中有它。你应该得到以下错误:
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
你也没有得到3,因为代码正在失败和退出,奇怪的是你没有看到错误。PS,它抛出了一个致命的错误,而不是一个异常,详细说明了为什么它没有捕获它。
以下是我通过命令行运行的代码:
<?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";
?>
您需要包含文件
include `myClass.php';
路径可能因文件结构而异。
Exist status 255是一个致命错误。您应该尝试将error_reporting
设置为E_ALL
error_reporting(E_ALL)
以确保没有错误被掩盖。这应该有助于你找出罪魁祸首。