Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #9914
| Message-ID | <3883513.ZhtQZqCeyo@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-06-28 12:39 +0200 |
| Subject | Re: how to change old ereg? |
| Newsgroups | comp.lang.php |
| References | <f60593e2-b741-40ba-9355-dcbfd41ac386@googlegroups.com> <71279fa6-1958-4b61-8758-14af767b1993@googlegroups.com> <kqjjfq$tsh$1@softins.clara.co.uk> |
Tony Mountifield wrote:
> Astrid <astrid.kuhr@gmail.com> wrote:
>> First all error-messages have gone now.
>> But now there is one coming back:
>>
>> Notice: Undefined offset: 6 in /var/www/html/phpweather/phpweather.php on
>> line 446
>>
>> Notice: Undefined offset: 7 in /var/www/html/phpweather/phpweather.php on
>> line 447
>>
>> elseif (preg_match('#^(VC)?' . /* Proximity */
>> '(-|\+)?' . /* Intensity */
>> '(MI|PR|BC|DR|BL|SH|TS|FZ)?' . /* Descriptor */
>> '((DZ|RA|SN|SG|IC|PL|GR|GS|UP)+)?' . /* Precipitation */
>> '(BR|FG|FU|VA|DU|SA|HZ|PY)?' . /* Obscuration */
>> '(PO|SQ|FC|SS)?$#', /* Other */
>> $part, $regs)) {
>> /*
>> * Current weather-group.
>> */
>> $decoded_metar['weather'][] =
>> array('proximity' => $regs[1],
>> 'intensity' => $regs[2],
>> 'descriptor' => $regs[3],
>> 'precipitation' => $regs[4],
>> 'obscuration' => $regs[6], /* line 446 */
>> 'other' => $regs[7]);
>>
>> }
>>
>> I tried with several delimiters, but the error is there.
>> How can I get it work?
>
> That probably means the optional Obscuration and Other were not present.
> Since nothing matched those parenthesised options, the corresponding
> captures were not put in the array.
>
> The quick and dirty solution, which I think is adequate in this instance,
Why?
> is to use @ to suppress the specific errors and allow the value to be
> null:
>
> array('proximity' => @$regs[1],
> 'intensity' => @$regs[2],
> 'descriptor' => @$regs[3],
> 'precipitation' => @$regs[4],
> 'obscuration' => @$regs[6], /* line 446 */
> 'other' => @$regs[7]);
>
> You should only use @ to suppress errors you already understand, and as
> close as possible to the specific location.
Or you could disable notices (they are _not_ error messages) entirely for
production, and enable them only for development, as it is recommended.
However, I have also received harmless Notices in development that hindered
development more than they helped because they broke the layout. In that
case I have used
if (defined('DEBUG') && DEBUG > 0)
{
error_reporting(error_reporting() & ~E_NOTICE);
}
/* code generating harmless notices */
if (defined('DEBUG') && DEBUG > 0)
{
error_reporting(error_reporting() | E_NOTICE);
}
This approach allows you to just set the debug level to toggle development
behavior instead of changing the (entire) code before deploying to
production. In my PHPX MVC framework, which is used by my ECMAScript
Support Matrix [1], and in the Matrix itself, DEBUG === 1 enables simple
debug messages, and DEBUG > 2 also enables database framework debug
messages.
PointedEars
___________
[1] <http://PointedEars.de/es-matrix>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to change old ereg? astrid.kuhr@gmail.com - 2013-06-25 21:41 -0700
Re: how to change old ereg? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-26 11:47 +0200
Re: how to change old ereg? Astrid <astrid.kuhr@gmail.com> - 2013-06-26 04:29 -0700
Re: how to change old ereg? tony@mountifield.org (Tony Mountifield) - 2013-06-26 11:57 +0000
Re: how to change old ereg? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-26 14:13 +0200
PREG \d vs. [0-9] (was: how to change old ereg?) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-06-26 16:42 +0200
Re: PREG \d vs. [0-9] Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-26 18:02 +0200
Re: how to change old ereg? Gregor Kofler <usenet@gregorkofler.com> - 2013-06-26 21:34 +0200
Re: how to change old ereg? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-27 01:18 +0200
Re: how to change old ereg? The Natural Philosopher <tnp@invalid.invalid> - 2013-06-27 12:55 +0100
Re: how to change old ereg? Astrid <astrid.kuhr@gmail.com> - 2013-06-26 05:24 -0700
Re: how to change old ereg? Astrid <astrid.kuhr@gmail.com> - 2013-06-28 01:38 -0700
Re: how to change old ereg? tony@mountifield.org (Tony Mountifield) - 2013-06-28 09:02 +0000
Re: how to change old ereg? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-28 12:39 +0200
Re: how to change old ereg? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-28 11:08 +0000
Re: how to change old ereg? Astrid <astrid.kuhr@gmail.com> - 2013-06-28 02:46 -0700
Re: how to change old ereg? Jerry Stuckle <jstucklex@attglobal.net> - 2013-06-28 08:48 -0400
csiph-web