我使用PHPUnit进行单元测试,但是当触发致命错误时,脚本会死,而且我没有正确的PHPUnit输出.
我希望PHPUnit输出保持正确格式化,因为它是由Eclipse的插件读取的.实际上,致命错误会停止PHPUnit,而在Eclipse中,插件无法解释任何内容(因为PHPUnit脚本有错误,而不是处理它).
谢谢
我有时会在生产中遇到这个错误:
if( true == $objWebsite ) {
$arrobjProperties = (array) $objWebsite->fetchProperties( );
if( false == array_key_exists( $Id, $Properties ) ) {
break;
}
$strBaseName = $strPortalSuffix . '/';
return $strBaseName;
}
$strBaseName = $strSuffix ;
return $strBaseName;
Run Code Online (Sandbox Code Playgroud)
我试图重现这个问题.但没有取得任何进展.$ Id,$收到价值的房产.
有谁知道什么时候'无法打破/继续1级'来自PHP?
我看过这篇帖子PHP Fatal错误:无法中断/继续.但没有得到任何帮助.
我使用以下脚本使用PHP使用数据库:
try{
$db = new PDO('mysql:host='.$host.';port='.$port.';dbname='.$db, $user, $pass, $options);
}
catch(Exception $e){
$GLOBALS['errors'][] = $e;
}
Run Code Online (Sandbox Code Playgroud)
现在,我想使用此数据库句柄使用此代码执行请求:
try{
$query = $db->prepare("INSERT INTO users (...) VALUES (...);");
$query->execute(array(
'...' => $...,
'...' => $...
));
}
catch(Exception $e){
$GLOBALS['errors'][] = $e;
}
Run Code Online (Sandbox Code Playgroud)
这是问题所在:
$GLOBALS['errors'][]数组,之后脚本仍在运行,注意:未定义的变量:第32行的C:\ xampp\htdocs [...]\test.php中的db
致命错误:在第32行的C:\ xampp\htdocs [...]\test.php中调用非对象的成员函数prepare()
注意:第32行是$query = $db->prepare(...)指令.
也就是说,脚本崩溃了,try/catch似乎没用.你知道为什么第二次尝试/捕获不起作用以及如何解决它?
谢谢您的帮助!
编辑:有一些非常好的回复.我已经验证了一个不是我想要做的,但这可能是最好的方法.
到目前为止我一直避免使用log.Fatal,但我最近偶然发现了这些问题; 代码覆盖和测试使用对数致命.
100个代码覆盖问题中的一条评论说:
...在绝大多数情况下,
log.Fatal应该只在main或init函数中使用(或者可能只是某些东西只能直接从它们调用)"
它让我思考,所以我开始查看Go提供的标准库代码.有很多例子,库中的测试代码使用log.Fatal它似乎很好.测试代码之外还有一些例子net/http,如下图所示:
// net/http/transport.go
func (t *Transport) putIdleConn(pconn *persistConn) bool {
...
for _, exist := range t.idleConn[key] {
if exist == pconn {
log.Fatalf("dup idle pconn %p in freelist", pconn)
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
如果最好的做法是避免使用log.Fatal,为什么在标准库中使用它,我本来希望只返回一个错误.对库的用户来说,os.Exit调用它并不提供应用程序清理的任何机会似乎是不公平的.
我可能是天真的,所以我的问题似乎是一个更好的实践似乎是呼唤log.Panic哪些可以恢复,我理论上长期稳定的应用可能有可能从灰烬中升起.
那么什么是最佳实践说Go应该什么时候应该使用log.Fatal?
有同样的问题,我是完全新的PHP.我安装XAMPP然后从wordpress下载孵化主题.当我运行index.php时,它会给我以下错误
"致命错误:在第1行的C:\ xampp\htdocs\hatch\index.php中调用未定义的函数get_header()"
任何人都可以帮助这个.谢谢
我收到以下错误:
Fatal error: Declaration of Shoppingcart::addToCart() must be compatible with that of Ishoppingcart::addToCart() in klassen.php on line 118
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?我找不到脚本:
<?php
// begin
interface Ishoppingcart{
public function addToCart();
public function printOverzicht();
}
abstract class Shoppingcart implements Ishoppingcart
{
protected $producten = array();
public function addToCart( Product $product) {
$this->producten[] = $product;
}
}
class Myshoppingcart extends Shoppingcart {
public function printOverzicht(){
echo ("<table border=1>
<tr>
<td colspan='7'>Bestellingoverzicht</td>
</tr>
<tr>
<td bgcolor=#cccccc> Product ID</td>
<td bgcolor=#cccccc> Beschrijving</td>
<td bgcolor=#cccccc> Merk</td>
<td bgcolor=#cccccc> …Run Code Online (Sandbox Code Playgroud) 我用三部手机测试我的应用程序(运行andorid版本:4.1.2 - 4.0.4 - 2.3.6).他们通过蓝牙交换数据没有问题,直到logcat中出现此错误并且手机完全关闭并重新启动.在此错误出现之前一切正常.
这是崩溃的手机上的logcat输出(运行版本4.1.2):
05-29 12:11:36.887: E/InputTransport(2947): channel '418655a8 Toast' ~ Could not create socket pair. errno=24
05-29 12:11:36.897: E/JavaBinder(2947): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
05-29 12:11:36.897: E/JavaBinder(2947): java.lang.RuntimeException: Could not open input channel pair. status=-24
05-29 12:11:36.897: E/JavaBinder(2947): at android.view.InputChannel.nativeOpenInputChannelPair(Native Method)
05-29 12:11:36.897: E/JavaBinder(2947): at android.view.InputChannel.openInputChannelPair(InputChannel.java:91)
05-29 12:11:36.897: E/JavaBinder(2947): at com.android.server.wm.WindowManagerService.addWindow(WindowManagerService.java:2295)
05-29 12:11:36.897: E/JavaBinder(2947): at com.android.server.wm.Session.add(Session.java:139)
05-29 12:11:36.897: E/JavaBinder(2947): at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:70)
05-29 12:11:36.897: E/JavaBinder(2947): at com.android.server.wm.Session.onTransact(Session.java:111)
05-29 12:11:36.897: E/JavaBinder(2947): at android.os.Binder.execTransact(Binder.java:367) …Run Code Online (Sandbox Code Playgroud) 我们正在使用一个封装数值的结构,我发现当这个结构的可空版本在表达式中使用时,FatalExecutionEngineError会发生:
附加信息:运行时遇到致命错误.错误的地址位于0x729c1e04,位于线程0x52d8上.错误代码是0xc0000005.此错误可能是CLR中的错误,也可能是用户代码的不安全或不可验证部分中的错误.此错误的常见来源包括COM-interop或PInvoke的用户编组错误,这可能会破坏堆栈.
我正在使用Visual Studio Premium 2013 Update 3这是源代码(C#,目标.NET Framework 4.5):
using System;
using System.Globalization;
namespace ConsoleApplication4
{
public struct Number
{
ValueType _val;
private Number(double val)
{
this._val = val;
}
public static implicit operator double(Number val)
{
return Convert.ToDouble(val._val, CultureInfo.InvariantCulture);
}
public static implicit operator Number(double val)
{
return new Number(val);
}
}
class Program
{
static void Main(string[] args)
{
Number? b = 1.2;
var c = b - 1.2;
Number b1 = 1.2;
var c1 …Run Code Online (Sandbox Code Playgroud) 好吧,我现在已经在这两个小时了,我看到其他人有这个错误,但我似乎无法与他的原因/决议相匹配.
致命错误:require()[function.require]:无法在第55行的/var/www/biztv_symfony/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php中重新声明类companycontroller
终端提供了一个更好的错误消息,指向我报告的实际类的结束子句(尝试重新声明).
如果我删除或重命名文件companyController.php它会抛出一个Symfony2错误,说它正在查找该类,但没有找到它在预期的位置.
如果我把文件放回原位,apache抛出一个php错误,说不能重新声明类companyController.
我只有一次吗?!
这是整个班级...如果有人有耐心尝试帮助我...
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use BizTV\BackendBundle\Entity\company;
use BizTV\BackendBundle\Form\companyType;
/**
* company controller
*
*/
class companyController extends Controller
{
/**
* Lists all company entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('BizTVBackendBundle:company')->findAll();
return $this->render('BizTVBackendBundle:company:index.html.twig', array(
'entities' => $entities
));
}
/**
* Finds and displays a company entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('BizTVBackendBundle:company')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find company entity.'); …Run Code Online (Sandbox Code Playgroud) 不知道发生了什么,但下面是日志在尝试访问phpmyadmin时给我的,请帮忙.试图调试一个不同的问题,并遇到这个问题.真的不可能恢复到工作的时候.
PHP致命错误:在第177行的/usr/share/php/gettext/gettext.inc中调用未定义的函数mb_detect_encoding()
当我试图访问该网站时,我收到此错误,我认为这两个错误很可能是相关的:
数据库连接错误(1):MySQL适配器'mysqli'不可用.
fatal-error ×10
php ×6
.net ×1
android ×1
bluetooth ×1
c# ×1
clr ×1
go ×1
if-statement ×1
phpmyadmin ×1
phpunit ×1
symfony ×1
try-catch ×1
undefined ×1