473,326 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Notices

I'm still coming to grips with Notices, particularly on missing indexes.

Lets say we have a form full of check boxes. An unchecked checkbox is
not sent in $_REQUEST and if you do something with
$_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
dealing with this?

I'm a recovering perl programmer so conciseness is still important. I
suppose I'll get over it eventually but I still miss ||= .

Jeff
Aug 9 '08 #1
3 1035
On Aug 9, 9:11*pm, Jeff <jeff@spam_me_not.comwrote:
* *I'm still coming to grips with Notices, particularly on missing indexes.

* *Lets say we have a form full of check boxes. An unchecked checkboxis
not sent in $_REQUEST and if you do something with
$_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
dealing with this?

* *I'm a recovering perl programmer so conciseness is still important.. I
suppose I'll get over it eventually but I still miss ||= .

* *Jeff
A typical solution is to configure your PHP to not show notices
anymore, for they are annoying.

Alternatively, you may test if there really is a
$_REQUEST['my_checkbox'] with either of the following:
isset($_REQUEST['my_checkbox'])
array_key_exists('my_checkbox', $_REQUEST)

Of course, isset() is a language construct rather than a function.
That is why you do not get a notice, even though it looks like you are
referencing $_REQUEST['my_checkbox'].
Aug 9 '08 #2
Jeff wrote:
I'm still coming to grips with Notices, particularly on missing indexes.

Lets say we have a form full of check boxes. An unchecked checkbox is
not sent in $_REQUEST and if you do something with
$_REQUEST['my_checkbox'] you'll get a notice. Is there a clean method of
dealing with this?

I'm a recovering perl programmer so conciseness is still important. I
suppose I'll get over it eventually but I still miss ||= .

Jeff
You should NEVER configure a development server to ignore notices. Each
one is a potential bug in your program - which is why they are being
displayed. They are notices to let you know there MAY be a problem. A
good programmer will fix these notices.

And it's easy to do. Just use isset() to determine of the checkbox is
set, or not, i.e.

$my_checkbox = isset($_POST['my_checkbox']) ? $_POST['my_checkbox'] : '';

The last value can be an empty string, null, 0 or whatever you want for
a value when the checkbox is not set.

Also, you should always user $_POST or $_GET instead of $_REQUEST.
$_REQUEST gets its data from $_GET, $_POST or $_COOKIE, and can too
easily cause problems (i.e. what happens if two years from now,
somewhere else in your program, you call setcookie('my_checkbox', 1)?

This code could break, among other things.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 9 '08 #3
Message-ID: <PZ******************************@earthlink.comfro m Jeff
contained the following:
>But missing index notices are NEVER harmless! They may not cause a
problem now. But they will later.

I remain skeptical that an undef has more harmful potential than an
empty string.
when I first started with PHP you used to see a lot of

if($var){...}

in tutorials. So naturally I did the same. Recently I was updating an
old website and I saw that a notice had appeared. Clearly the ISP had
changed its PHP version to one with a higher level of error reporting.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Aug 13 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Erwin Moller | last post by:
Hi group, I have this very annoying problem during development: the linenumbers PHP says contain a error/warning/notice are completely wrong. When? When I use includes and make a mistake. ...
6
by: Krishna Srinivasan | last post by:
I have a form with check boxes. When accessing a check box element that is not checked, I get a notice (Notice: Undefined variable..). Is there a way to hide these notices and warning in PHP code...
7
by: Jukka K. Korpela | last post by:
It occurred to me that it seems to be fairly easy to make visually strong elements turn into normal elements or disappear. The need for such effects arises when we wish to do everything possible to...
5
by: comp.lang.php | last post by:
I have a PHP script that has only one line: <?php error_reporting(E_ALL & ~E_NOTICE); ?> When run as CLI PHP I get an extremely large number of warnings, errors and notices, all related to the...
26
by: Craig Morrison | last post by:
I'm getting this: PHP Notice: Undefined index: D1 in /var/www/html..... From this line of code: $id_option = $_POST; Which is posted by this:
2
by: Sal | last post by:
I have error_reporting set at E_ALL | E_STRICT and get 35 Strict Standards notices every time I load MDB2. Is this something to be concerned about, and is this typical of other PEAR packages?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.