Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16975
| From | Matthew Carter <m@ahungry.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: PHP Warning: extract() expects parameter 1 to be array |
| Date | 2016-08-23 01:26 -0400 |
| Organization | Ahungry (http://ahungry.com) |
| Message-ID | <87oa4kukc5.fsf@ahungry.com> (permalink) |
| References | (3 earlier) <18d88f90-6b3b-4e2f-8b9f-5cb9c69176a1@googlegroups.com> <210820161026199601%timstreater@greenbee.net> <87pop2unf0.fsf@bsb.me.uk> <10692138.PaQTzsjEax@PointedEars.de> <npg0vd$b3k$1@jstuckle.eternal-september.org> |
Jerry Stuckle <jstucklex@attglobal.net> writes:
> On 8/22/2016 3:34 PM, the troll Thomas 'Pointed Head' Lahn wrote:
>> Ben Bacarisse wrote:
>>
>>> […] I prefer the "more structured" version:
>>>
>>> if ($argc < 2)
>>> echo "Please, provide a path to a file\n";
>>> else if (!file_exists($file))
>>> echo "Sorry, there is no such file $file\n";
>>> else if (!is_readable($file))
>>> echo "$file is not readable\n";
>>> ...
>>> else if (($open_file = fopen($file, "r")) === false)
>>> echo "Sorry, couldn't open $file\n";
>>> else {
>>> // All ok. Let's get on with it...
>>>
>>> while (...)
>>> {
>>> // Main work is here
>>> }
>>> }
>>
>> This code style is a maintenance nightmare (the missing blocks and the
>> assignment in the “if” statement doubly so). Do you know what the condition
>> on line 50 was because of which you wrote “else” on line 100?
>>
>
> Yes - if the code is properly indented and commented (something you
> wouldn't understand).
>
>> Also, PHP is influenced by C, but it is _not_ C. The function should throw
>> (PHP Standard Library) exceptions like \InvalidArgumentException instead of
>> echo-ing error conditions without regard to the user’s locale. This will
>> also get them a stack trace (even better if the Xdebug extension is
>> installed and enabled) if they do not catch the exception. As a result, the
>> then-unnecessary “else” statements would vanish in a puff of program logic.
>>
>
> Which would display to a user internal details of your code - a huge
> security exposure. But you don't understand security, either, do you?
>
> In addition, it will immediately stop processing of the page - resulting
> in invalid HTML being sent to the browser. Something else you don't
> care about, either.
>
>> <http://php.net/manual/en/language.exceptions.php>
>>
>
> Glad you can cut/paste a URL. Too bad you don't understand how write
> good PHP code.
Details of stack traces are only exposed if the environment
(production?) is configured to match that of a developer environment
(such as showing errors vs logging them).
It is also quite easy to wrap your outer-most layer of code input/output
in a try/catch block and handle:
- Rendering a generic or descriptive error message for the user in the
catch block
- Manually logging the stack trace (part of the \Exception object) to a
file or sending as part of an email to the webmaster (if this is not
configurable in the php.ini of the server for some reason)
- Ensuring the HTML the user receives is still valid
This also allows for easier to extend code in the future, as you end up
with a single exit point.
--
Matthew Carter (m@ahungry.com)
http://ahungry.com
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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