Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #16954

Re: PHP Warning: extract() expects parameter 1 to be array

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: PHP Warning: extract() expects parameter 1 to be array
Date 2016-08-20 19:28 +0200
Organization solani.org
Message-ID <npa3ut$o8r$1@solani.org> (permalink)
References <2d416b5e-e923-4d44-bcbf-6956d2436ef2@googlegroups.com> <57b8892b$0$876$e4fe514c@news.xs4all.nl> <6ee0e256-b008-4d76-8336-3eac5e4fe4c7@googlegroups.com>

Show all headers | View raw


On 20.08.2016 at 19:16, Alla wrote:

> Ruby, thank you very much. I have added the lines below to check what's causing 
> the issue:
> 
> else
>         {
>             $row_number = 0;
>             while(!feof($open_file))
>             {
>                 $new_entry = fgetcsv($open_file, 0, "\t");
>                 // var_dump($new_entry);
>                 $row_number++;
>                 
>                 if($new_entry == FALSE)

This tests doesn't work as you expect.  Actually, it will be true for
$new_entry === NULL and all other values that convert to boolean false.

I suggest to read the "Comparison Operators" section in the PHP manual
(<http://php.net/manual/en/language.operators.comparison.php>) and also
the section on "Type Juggling"
(<http://php.net/manual/en/language.types.type-juggling.php>).

>                     exit ("A problem reading data from the file; row number $row_number\n");
>                 if($new_entry == NULL)
>                 {
>                     echo "The line $row_number doesn't contain any data\n";
>                     continue;
>                 }
>                 
>                 extract($new_entry); 
> ......
> and I have found the problem - the last line in txt, i.e. 40796 line, is an empty one, it 
> contains no data, hence $new_entry is an empty string at that last while loop iteration -
> nothing to extract(). 

Generally, I suggest to use a while loop as shown in the example #1 in
the PHP manual:
<http://php.net/manual/en/function.fgetcsv.php#refsect1-function.fgetcsv-examples>.

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PHP Warning:  extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 09:15 -0700
  Re: PHP Warning:  extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 18:48 +0200
    Re: PHP Warning:  extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 10:16 -0700
      Re: PHP Warning: extract() expects parameter 1 to be array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-20 19:28 +0200
        Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 11:00 -0700
      Re: PHP Warning:  extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 21:05 +0200
    Re: PHP Warning:  extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 10:58 -0700
  Re: PHP Warning:  extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-20 18:21 +0100
    Re: PHP Warning: extract() expects parameter 1 to be array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-20 20:16 +0200
      Re: PHP Warning: extract() expects parameter 1 to be array "R.Wieser" <address@not.available> - 2016-08-20 21:26 +0200
        Re: PHP Warning: extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-20 22:05 +0100
      Re: PHP Warning: extract() expects parameter 1 to be array Alla <modelling.data@gmail.com> - 2016-08-20 22:39 -0700
        Re: PHP Warning: extract() expects parameter 1 to be array Tim Streater <timstreater@greenbee.net> - 2016-08-21 10:26 +0100
          Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-21 10:10 -0400
          Re: PHP Warning: extract() expects parameter 1 to be array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-21 16:55 +0100
            Re: PHP Warning: extract() expects parameter 1 to be array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-22 21:34 +0200
              Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-22 19:13 -0400
                Re: PHP Warning: extract() expects parameter 1 to be array Matthew Carter <m@ahungry.com> - 2016-08-23 01:26 -0400
                Re: PHP Warning: extract() expects parameter 1 to be array Jerry Stuckle <jstucklex@attglobal.net> - 2016-08-23 08:08 -0400

csiph-web