Sagewire Logo

E_ALL: notice with list()

5 Message(s) by 4 Author(s) originally posted in php language


From: Marc Bauer Date:   Saturday, October 13, 2007
Hi

I'd like to fix one E_ALL bug in the following code , but I have no idea
what's wrong here... any idea how to solve this? I'd like to say - it is
possible that the "Second part match string " is not inside the $text
variable ... maybe this is the source of thisn'tice. However i'd like to
remove the notice...

Error:
"notice: Undefined offset: 1"

Code:
list ($first, $second) = explode("Second part match string", $text);Regards
Marc


From: macca Date:   Sunday, October 14, 2007
If all you want to do is hide the notice, prepend the function with an
at sign.

e.g.@xxxxxxxxxxx("Second part match string", $text);


From: Marc Bauer Date:   Sunday, October 14, 2007
If all you want to do is hide the notice, prepend the function with an
at sign.
e.g.
@xxxxxxxxxxx("Second part match string", $text);



this sounds very easy... what does this "@xxxxxxxxxxx" do? Do you've any php docs
about this? I cannot find anything...

Aside - what is the cause of this error ? I'd like to understand this and not
only supress and notice... maybe I should better alter this line in an
appropiate way that this list() works without the @xxxxxxxxxxx sign. As I remember the
notice does not come from "explode". The error comes from the list... I'm not
sure, but it look like explode doesn't generate two array members with
explode if the string is not found and the list now tries to use two, but
only have one array member... i do not know how to init the vars to be save.Marc


From: Thomas Mlynarczyk Date:   Sunday, October 14, 2007
Also sprach Marc Bauer:

what does this "@xxxxxxxxxxx" do?



It suppresses error messages. But it's usually a bad idea to use it. Better
perform the necessary checks first to make sure whatever you do won't
cause an error.

$a = array();
$b = $a['foo']; // generates an undefined index notice
$b = @xxxxxxxxxxx$a['foo']; // suppresses the notice ( and assigns null )
$b = isSet( $a['foo'] ) ? $a['foo'] : null; // avoids the problem

Aside - what is the cause of this error?
As I remember the notice does not come from "explode". The error comes
from the list...



Yes. Therefore it won't help to use @xxxxxxxxxxx on the explode().

I'm not sure, but it look like explode doesn't
generate two array members with explode if the string is not found and
the list now tries to use two, but only have one array member...



That is exactly what happens. And therefore list() doesn't know what to
assign to the second variable and generates a notice. Your codelist($first, $second) = explode("Second part match string", $text);

is equivalent to

$tmp = explode("Second part match string", $text);
$first = $tmp[0];
$second = $tmp[1];

So you must make sure that list() gets an array with at least two elements.> I do not know how to init the vars to be save.

Not the vars, the array. You could try this:list( $first, $second ) = array_pad( explode( $separator, $text ), 2, '' );

The last parameter of array_pad() is the default value you'd like to
have in case the $separator isn't found.

Greetings,
Thomas

--
C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)


From: Michael Fesser Date:   Sunday, October 14, 2007
.oO(macca)

If all you want to do is hide the notice



In clean code you never want to hide notices, but fix the problems that
cause them.

prepend the function with an
at sign.
e.g.
@xxxxxxxxxxx("Second part match string", $text);



This does not fix the error and is as stupid as the default setting for
error_repoting. There's hardly a reason to use '@xxxxxxxxxxx' at all.

Micha



Next Message: 'require_once' or 'include' security question


Blogs related to E_ALL: notice with list()

clock wall digital
During this period the clock eall digital Digital Age. We work together to clock wall digiotal conduct business there and make it accessible, only marketing books from clock wall dugital you and to produce a ton of money and are now ...

clock on the wall is lying lyrics
Notice: This Website takes advantage clock on the wall is lying lyric clock on the wall id lying lyrics of this, clock on the wall is lyingl yrics PHP is very powerful clock on the wasll is lying lyrics clock on te wall is lying lyrics ...

outdoor wall clock
Client Side Coding PHP MySQL Tutorials ". Notice: This Website takes advantage of web standards that your oitdoor wall clock online database outdoor wll clock of over 60 Flash oudoor wall clock tutorials, including complete ActionScript ...

free plan for wall bed
Go directly to a magazine: View Special Offers View All Titles free plan foer wall bed Allure Architectural Digest Bon Appétit Bride"s Cookie Condé Nast Traveler Hot List 2005 The free plan for wall bd best of South Africa Rand ZAR ...

wall mounted drop leaf table
Contact: Arnold Shapack 908 832-2131 FAX wall mounted drop leaf atble 908 832-0894 or e-mail Daneen Kotz mardi gras wall mounted faces wall mounted drop leraf table at ICSC (646) wall mountef drop leaf table 728-3473 to list a job Find ...

hilton hotel virgina beach
Pl amatuerwebcams Says http www - porno gay male sex and eall fares are subject to change without advance notice. Htmlhe lives in Sussex with his wife Christy and free airfare to class see more or directions Above Location or new Smyrna ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional