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


Groups > comp.lang.php > #16962

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

From Tim Streater <timstreater@greenbee.net>
Newsgroups comp.lang.php
Subject Re: PHP Warning: extract() expects parameter 1 to be array
Date 2016-08-21 10:26 +0100
Message-ID <210820161026199601%timstreater@greenbee.net> (permalink)
References <2d416b5e-e923-4d44-bcbf-6956d2436ef2@googlegroups.com> <200820161821375934%timstreater@greenbee.net> <npa6ob$q4u$1@solani.org> <18d88f90-6b3b-4e2f-8b9f-5cb9c69176a1@googlegroups.com>

Show all headers | View raw


In article <18d88f90-6b3b-4e2f-8b9f-5cb9c69176a1@googlegroups.com>,
Alla <modelling.data@gmail.com> wrote:

>On Saturday, August 20, 2016 at 9:15:44 PM UTC+3, Christoph M. Becker wrote:
>> On 20.08.2016 at 19:21, Tim Streater wrote:
>> 
>> > In article <2d416b5e-e923-4d44-bcbf-6956d2436ef2@googlegroups.com>,
>> > Alla <modelling.data@gmail.com> wrote:
>> > 
>> >>                $new_entry = fgetcsv($open_file, 0, "\t");
>> > 
>> > Why are you not checking that fgetcsv didn't return a boolean?
>> > 
>> > I could also ask why your program is such a convoluted if/then/else
>> > mess but I can't be bothered.
>> 
>> Alla is learning.  No one is born a master. :-)

>Christoph and Rudy, Thank you very much!
>As to Tim's message, which I can see only as a quotation here, I am fine with 
>all criticism, even harsh one, but if it contains correct remarks, as Tim's
>message 
>does, - it is also very helpful in learning. And I do agree
>about the "convoluted mess"; I am struggling with this issue,
>including in my C coding experience. I am in the processes, hopefully a successful
>one eventually :)

There was a time around 1980 when computer science students were
apparently being told that single-entry-single-exit was the way to
write functions and procedures. This approach was assisted by the fact
that Pascal didn't even have a return statement.

I've always found this approach to be foolish as it increases
complexity for no benefit, and on the one occasion when I was forced to
write a substantial piece of code in Pascal, I used to systematically
put a 999: label at the end of the function, to which I could GOTO when
needed.

In my view, you should be doing thus:

// Start with all tests for conditions that prevent the program being
run

if  ($argc<2)
     {
     echo "Please, provide a path to a file\n";
     exit ()
     }

if  (!file_exists($file))
     {
     echo "Sorry, there is no such file $file\n";
     exit ()
     }

if  (!is_readable($file))
     {
     echo "$file is not readable\n";
     exit ()
     }

// other tests etc, then finally:

$open_file = fopen($file, "r");
if  ($open_file===false)
     {
     echo "Sorry, couldn't open $file\n";
     exit ();
     }

// Now comes the real meat of the program

while (...)
     {

     // Main work is here

     }


This sort of approach is, IMO, much more readable. Get the error
checking out of the way first. Then you can concentrate on what it is
you really want to do with the program without having to worry whether
your if/then/else nesting is correct - because there isn't any!

Now I'm off to a family picnic at Polesden Lacey.

-- 
"... you must remember that if you're trying to propagate a creed of 
 poverty, gentleness and tolerance,  you need a very rich, powerful,
 authoritarian organisation to do it."             - Vice-Pope Eric

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