Re: how to change old ereg? [message #181962 is a reply to message #181959] |
Fri, 28 June 2013 10:39 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Tony Mountifield wrote:
> Astrid <astrid(dot)kuhr(at)gmail(dot)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
|
|
|