当 var 很大时 return var 不起作用?
所以我使用 PHPExcel (http://phpexcel.codeplex.com/) 导入 Excel 工作表。在我的开发系统上一切工作正常,但在实时系统上却不太工作。
因此我进行了调试并查看了可能出现的问题。我发现一个方法显然返回了 NULL,而它应该返回一个对象。我研究了该方法,并 var_dump()
编辑了该方法中返回的 var。 var 不是空伪
代码:
class Bar()
{
function methodInAClass()
{
$test = new Foobar;
[...]
/* $test was an object here with a lot of data (var_dump()
* took around 100.000 lines in an editor) */
var_dump($test);
return $test;
}
}
$bar =& new Bar();
$test2 = $bar->methodInAClass(); //$test2 is NULL here
我做错了什么?这是来自 php.ini 的问题吗?
So I am using PHPExcel (http://phpexcel.codeplex.com/) to import a excel sheet. everything works fine on my development system, BUT it doesn't quite work on the live system.
Hence I debugged and looked what could be wrong. I got to a point where I found that a method obviously returned NULL, where it should have returned an object. I looked into that method, and var_dump()
ed the var which was returned in the method. the var was NOT NULL
PSEUDO CODE:
class Bar()
{
function methodInAClass()
{
$test = new Foobar;
[...]
/* $test was an object here with a lot of data (var_dump()
* took around 100.000 lines in an editor) */
var_dump($test);
return $test;
}
}
$bar =& new Bar();
$test2 = $bar->methodInAClass(); //$test2 is NULL here
What am I doing wrong? Is this a problem that comes from the php.ini?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果返回的是实际对象(就像在本例中一样),PHP 不应该关心返回值有多大。更明确的细节可能会有所帮助,因为您引用的示例应该可以正常工作......我对 PHPExcel 有一定的了解。您使用什么版本?您要返回什么对象? (IIRC 库中没有 Foobar 对象)您是否使用任何内存缓存?
PHP shouldn't care how big the returned value is if it's the actual object being returned (as it is in this case). More explicit detail might help, because your quoted example should work without issue... I have some familiarity with PHPExcel. What version are you using? What object are you returning? (IIRC there isn't a Foobar object in the library) Are you using any memory caching?
我认为没有理由发生这种情况。除非你正在做一些有趣的事情,否则你不会向我们展示,否则我不知道如何在没有本机调试器的情况下检查这一点,例如,你可以在对象的内容上放置数据断点。
顺便说一句,您没有理由这样做
$bar =& new Bar();
而不是$bar = new Bar();
(在 PHP5 中);事实上,前者已被弃用。I see no reason for this happen. Unless you're doing something funny you're not showing us, I don't see how you could check this out without a native debugger, where you could, for instance, put a data breakpoint on the contents of the object.
And by the way, there's no reason you should do
$bar =& new Bar();
instead of$bar = new Bar();
(in PHP5); in fact, the former is deprecated.更高的内存限制似乎已经解决了这个问题!
A higher memory limit seems to have fixed the issue!