我使用ErrorException作为错误和异常的中央错误处理函数:
例子:
set_error_handler('my_error_handler');
set_exception_handler('my_exception_handler');
function my_error_handler ($errno, $errstr, $errfile, $errline)
{
my_exception_handler(new ErrorException($errstr, 0, $errno, $errfile, $errline));
}
function my_exception_handler ($e)
{
echo $e->getSeverity();
echo $e->getCode();
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
现在它只出现在默认值$e->getSeverity();中ErrorException而不是在默认值中Exception;
因为当throw new Exception('test');我得到一个Fatal error: Call to undefined method Exception::getSeverity().
但是当我throw new ErrorException('test');按预期工作时。
这似乎合乎逻辑,但有没有一种方法我仍然可以使用throw new Exception('test');而不会出现致命错误?大多数第三方库都使用Exception(不是ErrorException),所以当出现第三方异常时会出现问题,会导致Fatal Error。我该如何解决这个问题?
例如:
server-a.com/test.php的内容:
echo 'hello world one';
// now I need to call server-b.com/test.php here silently
// without interfering with user experience
echo 'hello world two';
Run Code Online (Sandbox Code Playgroud)
server-b.com/test.php的内容:
mail($foo, $bar, $qux); header('location: http://google.com');
现在运行server-a.com/test.php应该输出hello world one hello world two. 即使server-b.com/test.php调用成功,它也不应该重定向到 google.com。
我在https://developers.facebook.com/tools/explorer页面上获取了访问令牌,我的应用程序可以在Facebook页面的墙上发布.
然而,access_token一小时后过期.
我如何获得不到期access_token?
编辑:失败的选民:我已经发布了自己的答案,如果你读了它,你就会知道我的解决方案永远不会在FB文档中找到,也不会在SO中找到.
我需要使用MySQL中的特定功能,我不确定其他数据库风格是否可用.例如,
SELECT DATE_SUB(mydate, INTERVAL 5 DAY) AS foo FROM table
使用PDO时,这种情况的最佳做法是什么?
编辑:
我的意思是,我怎样才能确保DATE_SUB在支持PDO的所有DB风格中都能使用?
<?php
namespace Vendor\Package;
$test1 = new Foo\Bar(); // works as usual
$test2 = 'Foo\Bar';
$test2 = new $test2(); // does not work
$test3 = 'Vendor\Package\Foo\Bar';
$test3 = new $test3(); // but this works
Run Code Online (Sandbox Code Playgroud)
我正在寻找使用$test2但它不起作用,即使它看起来应该,因为它几乎与$test3工作相同.
这是预期的还是我需要使用一些语法test2来工作?
以下示例打印2147483647而不是13757966641806459594
$i = '13757966641806459594';
echo (int) $i;
Run Code Online (Sandbox Code Playgroud)