Older Contests
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP ContestsOlder Contests

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old May 30th, 2004, 09:02 AM
jorgen jorgen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Hardenberg, Holland<marquee>
Posts: 284 jorgen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
[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

...

Reply With Quote
  #2  
Old May 30th, 2004, 09:07 AM
jorgen jorgen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Hardenberg, Holland<marquee>
Posts: 284 jorgen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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? ;)

Reply With Quote
  #3  
Old May 30th, 2004, 09:31 AM
cirox cirox is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 cirox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to cirox
[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.

Reply With Quote
  #4  
Old May 30th, 2004, 09:59 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
[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:

php Code:
Original - php Code
  1.  
  2. $foo[bar] = 'enemy';
  3. echo $foo[bar];
  4. // etc
  5.  


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.

php Code:
Original - php Code
  1.  
  2.     error_reporting(E_ALL);
  3.     ini_set('display_errors', true);
  4.     ini_set('html_errors', false);
  5.     // Simple array:
  6.     $array = array(1, 2);
  7.     $count = count($array);
  8.     for ($i = 0; $i < $count; $i++) {
  9.        echo "nChecking $i: n";
  10.        echo "Bad: " . $array['$i'] . "n";
  11.        echo "Good: " . $array[$i] . "n";
  12.        echo "Bad: {$array['$i']}n";
  13.        echo "Good: {$array[$i]}n";
  14.     }
  15.      


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]]++;

Reply With Quote
  #5  
Old May 30th, 2004, 01:18 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
[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]]++;

Reply With Quote
  #6  
Old May 30th, 2004, 02:28 PM
fidian fidian is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 45 fidian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
[appleeaters]RE: notices in robotslib.php

If I'm reading this correctly, it should be
php Code:
Original - php Code
  1. $this->i_apples["{$args[1]};{$args[2]}"] = 1

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 ++.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP ContestsOlder Contests > [appleeaters]notices in robotslib.php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway