声明空数组,填充并迭代麻烦 – PHP

我写了一个脚本来阅读Netflix目录并填充我的数据库.一切都很好,作为一个Web脚本(超时除外)所以我转移到直接从控制台调用.

我注意到一些奇怪的东西,比如__construct()不再被调用(但是这很容易使用类名作为函数来补救.

现在我不能像以前那样让我的阵列工作,这是一般的想法.

(其实我尝试了几种组合,所以我会分享它们)

1 – 这在web脚本版本中工作得很好,不再适用于从控制台调用

//declare empty
var $genreArray=array();

//later I add values one at a time as the XML is parsed
array_push($this->genreArray,$attrs['term']);

//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
    // never gets called - array seen as empty
    $this->db->linkGenre($value,$this->title_uid);
}

2 – 所以我尝试了PHP手册;推荐 – 没什么

//declare empty
var $genreArray=array();

//later I add values one at a time as the XML is parsed
$this->genreArray[]=$attrs['term'];

//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
    // never gets called - array seen as empty
    $this->db->linkGenre($value,$this->title_uid);
}

3 – 所以最后我尝试手动跟踪索引

//declare empty array
var $genreArray=array();
var $gi=0;

//later I add values one at a time as the XML is parsed
$this->genreArray[$this->gi++]=$attrs['term'];

//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
    // never gets called - array seen as empty
    $this->db->linkGenre($value,$this->title_uid);
}

所以我现在完全被难倒了.

有没有人声明空数组并通过控制台填充?

(所有这3个都通过网络工作 – 所以我需要一个控制台专家)

感谢您的支持,以下是要求的其他详细信息;

PHP -v

PHP 4.4.9(cli)(建于:2008年9月17日12:02:18)
版权所有(c)1997-2008 PHP小组
Zend Engine v1.3.0,版权所有(c)1998-2004 Zend Technologies
    Zend Technologies的Zend Extension Manager v1.2.2,版权所有(c)2003-2007
    使用Zend Optimizer v3.3.3,版权所有(c)1998-2007,Zend Technologies

每个片段都在单独的运行中尝试过.您对该课程有哪些细节感兴趣?

我已经使用echo语句来验证代码是否按预期调用.如果我通过URL点击脚本,一切都会很好(对于前几千条记录,直到超时).

没有错误被抛出,我甚至尝试添加

error_reporting(E_ALL);
ini_set('display_errors', true);

解决方法:

I noticed a few oddities, like __construct() no longer being called (but that was easily remidied using the class name as a function.

听起来你的命令行和Web服务器PHP是不同的版本.你的CLI是PHP 4吗?函数PHPversion()将告诉您CLI和Web中的版本.

你检查过错误日志了吗?你没有提到它,但那将是第一个看的地方.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...