Вопрос

PHP Notice:  Undefined index: parentid in /home/public_html/data/Dataset.php on line 319
PHP Notice:  Undefined index: destinations in /home/public_html/data/Dataset.php on line 330
PHP Notice:  Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice:  Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice:  Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice:  Undefined index: radiogroup in /home/public_html/data/Dataset.php on line 340
PHP Notice:  Undefined index: name in /home/public_html/data/Dataset.php on line 220
PHP Notice:  Undefined index: fieldhelp in /home/public_html/data/Dataset.php on line 236

My script refuses to work after upgrading to php 5.3 from 5.2. I am seeing many PHP Notice in the log.

at line 319: if( $this->aFields["parentid"] ) {

at line 340: if( $curField["radiogroup"] ) {

I suspect the problem is in another file which contains many such lines

 if( isset( $this->request_vars[$name]["id"] ) ) {

how do i fix this? if it's that easy by judging from above.

Это было полезно?

Решение

It's not an error. It says that there's no element with index "radiogroup" etc. in array $curField.

You have to check if is it present first using isset, for example:

if(isset($curField['radiogroup']) and $curField['radiogroup']) {

Другие советы

Undefined index means that you try to access a key of an associative array that doesn't exist. This should be present in your old configuration but due to the error reporting level it never came up.

You should alter your code in order to first test if the variable is set and then use it.

For example:

Change occurrences of the form:

if( $this->aFields["parentid"] ) {
   ...
}

to

if( isset($this->aFields["parentid"]) ) {
   ...
}

From the PHP documentation (error_reporting):

<?php
// Turn off all error reporting
error_reporting(0);
?>

Other interesting options for that function:

<?php

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

Hard to tell from the code, but I presume the error reporting level has changed, making it now display notices. However, if its possible a variable may not exist, you should use something like:

if( isset($this->aFields["parentid"]) ) {

In your case you could use empty, as that would check its both set and has a value and its not equal to 0/false (same as original line)

if( ! empty($this->aFields["parentid"]) ) {
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top