Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclare empty array, populate and iterate troubles - PHP
    primarykey
    data
    text
    <p>I wrote a script to read the Netflix catalog and populate my DB. <strong>Everything worked fine as a web script</strong> (except for timeouts) so I shifted to <strong>calling directly from the console</strong>.</p> <p>I noticed a few oddities, like __construct() no longer being called (but that was easily remedied using the class name as a function.</p> <p>Now I <strong>can't get my arrays to work as before</strong>, here's the general idea.</p> <p>(Actually I have tried a few combinations, so I'll share them all)</p> <p>1 - this worked in the web script version just fine, no longer works calling from console</p> <pre><code>//declare empty var $genreArray=array(); //later I add values one at a time as the XML is parsed array_push($this-&gt;genreArray,$attrs['term']); //after I have parsed an entire "title" element, I iterate the array foreach ($this-&gt;genreArray as $value) { // never gets called - array seen as empty $this-&gt;db-&gt;linkGenre($value,$this-&gt;title_uid); } </code></pre> <p>2 - so I tried the PHP manual; recommendation - nothing</p> <pre><code>//declare empty var $genreArray=array(); //later I add values one at a time as the XML is parsed $this-&gt;genreArray[]=$attrs['term']; //after I have parsed an entire "title" element, I iterate the array foreach ($this-&gt;genreArray as $value) { // never gets called - array seen as empty $this-&gt;db-&gt;linkGenre($value,$this-&gt;title_uid); } </code></pre> <p>3 - so finally I tried manually tracking the index</p> <pre><code>//declare empty array var $genreArray=array(); var $gi=0; //later I add values one at a time as the XML is parsed $this-&gt;genreArray[$this-&gt;gi++]=$attrs['term']; //after I have parsed an entire "title" element, I iterate the array foreach ($this-&gt;genreArray as $value) { // never gets called - array seen as empty $this-&gt;db-&gt;linkGenre($value,$this-&gt;title_uid); } </code></pre> <p>So I am totally stumped now.</p> <p>Has anyone declared empty arrays and populated via console?</p> <p>(All 3 of these work via the web - so I need a console expert here)</p> <hr> <p><strong>Thanks for the support, here are the additional details requested;</strong></p> <p>php -v</p> <p>PHP 4.4.9 (cli) (built: Sep 17 2008 12:02:18) Copyright (c) 1997-2008 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies</p> <hr> <p>Each snippet was tried in a separate run. What details about the class are you interested in?</p> <p>I have used echo statements to verify that the code is being called as expected. And if I hit the script through a URL everything kicks off fine (for the first few thousand records until the timeout).</p> <hr> <p>No errors are being thrown, I even tried adding...</p> <pre><code>error_reporting(E_ALL); ini_set('display_errors', true); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload