|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
[appleeaters]notices in robotslib.php
Hi,
If one sets error_reporting(E_ALL), he gets several notices. So I guess robotslib.php is a little buggie. Code:
Notice: Undefined index: 6;1 in E:ContestTestingrobotslib.php on line 56 Notice: Undefined index: 2;2 in E:ContestTestingrobotslib.php on line 56 ... |
|
#2
|
|||
|
|||
|
[appleeaters]RE: notices in robotslib.php
I just read you suggested in another topic to use:
Code:
ini_set('error_reporting', 'E_ALL & ~E_NOTICE');
ini_set('error_reporting', 'E_ALL & ~E_WARNING');
But that does not fix the problem. Well, the notices do not appear anymore, but I want to see those notices. How am I able to write clean code with this dirty language without the notices? ;) |
|
#3
|
|||
|
|||
|
[appleeaters]RE: notices in robotslib.php
My guess is you're just being a bit too pedantic; a good thing for programming in general, but by practice, you often have to cut corners and sneak around in PHP. I believe the "problem" is generated while importing the values of the arrays into the script, incrementing an uninitalized variable ($this->i_apples["$args[1];$args[2]"]++;).
The fix would to be simply to initalize it, but since the game is about speed, it's faster just to ignore little issues like that and let Zend do its job. Just turn off warnings and notices and it'll go away. |
|
#4
|
|||
|
|||
|
[appleeaters]RE: notices in robotslib.php
(http://www.php.net/types.array)
Array do's and don'ts Why is $foo[bar] wrong? You should always use quotes around a string literal array index. For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You might have seen the following syntax in old scripts: This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string ('bar' - notice the quotes), and PHP may in future define constants which, unfortunately for your code, have the same name. It works because PHP automatically converts a bare string (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named bar, then PHP will substitute in the string 'bar' and use that. Note: This does not mean to always quote the key. You do not want to quote keys which are constants or variables, as this will prevent PHP from interpreting them. Note: The output from the above is: Checking 0: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 1 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 1 Checking 1: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 2 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 2 ------------------------------ the fix for $this->i_apples["$args[1];$args[2]"]++; should be $this->i_apples[$args[1] . ";" . $args[2]]++; |
|
#5
|
|||
|
|||
|
[appleeaters]RE: notices in robotslib.php
I think it should be:
$this->i_apples["{$args[1]};{$args[2]}"]++; or $this->i_apples[$args[1].';'.$args[2]]++; |
|
#6
|
|||
|
|||
|
[appleeaters]RE: notices in robotslib.php
If I'm reading this correctly, it should be
The ++ is incrementing a counter that does not exist. Also, apples can't share the same space. Therefore, you should just use "= 1" instead. The library I posted at http://rumkin.com/reference/php_contest/ uses "= 1" instead of ++. |
![]() |
| Viewing: Codewalkers Forums > PHP Contests > Older Contests > [appleeaters]notices in robotslib.php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|