<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Odd php error..</title>
		<link>http://www.allegro.cc/forums/view/590788</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 04 Apr 2007 18:32:21 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, I suck at coming up with topics, so sue me <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>I&#39;ve been working on two php apps today, and both are giving me the same headache. Some how, php is caching the code and only refreshing when it feels like it. And it doesn&#39;t happen all the time, I was making good progress all afternoon till a bout an hour ago...</p><p>Heres the error I get from php:
</p><pre>[Thu Mar 29 18:29:59 2007] [error] [client 192.168.1.20] PHP Fatal error:
mysql error: [1146: Table &#39;moodle.mdl_teachmeto_activeusers&#39; doesn&#39;t exist] in
EXECUTE(&quot;UPDATE mdl_teachmeto_activeusers SET lastactivity = &#39;2007-03-29 18:29:59&#39; WHERE userid = &#39;5&#39;&quot;)
in /var/www/.../htdocs/lib/adodb/adodb-errorhandler.inc.php on line 77, referer: <a href="http://.../chat/">http://.../chat/</a></pre><p>

And the funny thing? its right, that table doesn&#39;t exist, but it doesn&#39;t exist that way in the php code either. grep finds NO references to any mdl_teachmeto_* tables.</p><p>I&#39;m stuck trying to figure out why php+apache can&#39;t seem to notice the code has changed, and hacking with a couple third party apps and libs. All in JS and PHP, neither of which I like very much. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 05:36:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, you can specify the DB prefix in moodle, IIRC, so check for teachmeto_ references, as the mdl would be pulled from a configuration.</p><p>And, unless you have some type of caching setup, it will always execute the PHP every time the page is requested.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 05:55:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you tell us anything else? Maybe give us some code? What DBMS are you using? It appears related to ADOdb or the database.
</p><div class="quote_container"><div class="title">Thomas Fjellstrom said:</div><div class="quote"><p>
&quot;UPDATE mdl_teachmeto_activeusers SET lastactivity = &#39;2007-03-29 18:29:59&#39; WHERE userid = &#39;5&#39;&quot;
</p></div></div><p>

Is that your SQL or something from PHP? Should the 5 be in single-quotes...?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 05:55:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, you can specify the DB prefix in moodle, IIRC, so check for teachmeto_ references, as the mdl would be pulled from a configuration.
</p></div></div><p>Ah, the teachmeto stuff is an addition. Its not part of moodle, but it does access some of moodle&#39;s dirty bits.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And, unless you have some type of caching setup, it will always execute the PHP every time the page is requested.
</p></div></div><p>Good to know.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Can you tell us anything else?
</p></div></div><p>
Thats all I can think of, it just decides not to notice that some code has changed.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Maybe give us some code? What DBMS are you using? It appears related to ADOdb or the database.
</p></div></div><p>Using mysql and ADODB, through moodle&#39;s api.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Is that your SQL or something from PHP? Should the 5 be in single-quotes...?
</p></div></div><p>Its from php, or possibly moodle&#39;s api.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 05:59:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That SQL is fine, as far as the 5 being in quotes goes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 07:26:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Lets chock that one up to stupidity (mostly on the part of the original programmer &gt;:E)</p><p>Now I have another problem that I don&#39;t quite get:</p><pre>[Thu Mar 29 20:42:06 2007] [error] [client 192.168.1.20] PHP Catchable fatal error:
Object of class stdClass could not be converted to string in
/var/www/.../htdocs/chat/chat.php on line 345, referer: <a href="http://.../chat/">http://.../chat/</a></pre><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
$teachers = array(); ...<br />/* line 345 */ return array_unique($teachers);
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 07:44:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
That SQL is fine, as far as the 5 being in quotes goes.
</p></div></div><p>

It&#39;s like a dynamically typed SQL!? <i>{runs away crying}</i></p><p>Are most SQL implementations like that or only MySQL&#39;s?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 07:44:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That almost sounds like a running-php4-on-php5 or php5-on-php4 type of error.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It&#39;s like a dynamically typed SQL!? {runs away crying}
</p></div></div><p>

If you knew SQL you would know that (IIRC) you are actually supposed to quote everything like that, for security reasons.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 07:47:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I do know SQL and I&#39;ve never seen that before. In fact, if I&#39;m not mistaken SQL Server will return errors if you quote a numeric field.</p><p>What security benefit is there to quoting everything?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 07:48:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Apparently I am wrong. I&#39;ll take note that you are not &quot;supposed&quot; to quote your integral types. As far as I know it works either way, however.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 07:52:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ok, It may be a php version error, the person that wrote this crap up and ditched on my friend...</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>   function tmt_findMyTeachers<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">2</td><td>   <span class="k2">{</span></td></tr><tr><td class="number">3</td><td>       </td></tr><tr><td class="number">4</td><td>      global $USER<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>      $isTeacher <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>      $teachers <span class="k3">=</span> array<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>       </td></tr><tr><td class="number">8</td><td>      $COURSES <span class="k3">=</span> get_my_courses<span class="k2">(</span>$USER-&gt;id<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>       </td></tr><tr><td class="number">10</td><td>      foreach<span class="k2">(</span>$COURSES as $COURSE<span class="k2">)</span></td></tr><tr><td class="number">11</td><td>      <span class="k2">{</span></td></tr><tr><td class="number">12</td><td>          </td></tr><tr><td class="number">13</td><td>         $context <span class="k3">=</span> get_context_instance<span class="k2">(</span>CONTEXT_COURSE, $COURSE-&gt;id<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>         $myteachers <span class="k3">=</span> get_role_users<span class="k2">(</span><span class="n">3</span>, $context<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>         $myteacher2 <span class="k3">=</span> get_role_users<span class="k2">(</span><span class="n">4</span>, $context<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td>          </td></tr><tr><td class="number">17</td><td>         <span class="k1">if</span> <span class="k2">(</span>$myteachers<span class="k2">)</span></td></tr><tr><td class="number">18</td><td>            foreach <span class="k2">(</span>$myteachers as $teacher<span class="k2">)</span></td></tr><tr><td class="number">19</td><td>         array_push<span class="k2">(</span>$teachers, $teacher<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>          </td></tr><tr><td class="number">21</td><td>         <span class="k1">if</span> <span class="k2">(</span>$myteacher2<span class="k2">)</span></td></tr><tr><td class="number">22</td><td>            foreach <span class="k2">(</span>$myteacher2 as $teacher<span class="k2">)</span></td></tr><tr><td class="number">23</td><td>         array_push<span class="k2">(</span>$teachers, $teacher<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>          </td></tr><tr><td class="number">25</td><td>      <span class="k2">}</span></td></tr><tr><td class="number">26</td><td>       </td></tr><tr><td class="number">27</td><td>      <span class="k1">return</span> array_unique<span class="k2">(</span>$teachers<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>       </td></tr><tr><td class="number">29</td><td>   <span class="k2">}</span></td></tr></tbody></table></div></div><p>

From my <u>Very</u> limited knowledge of php, I&#39;d say that looks ok...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 07:54:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I looked it up on dev.mysql.com. Apparently MySQL will convert between types when necessary. So if you tried:<br /><span class="source-code">SELECT <span class="n">1</span> <span class="k3">+</span> <span class="s">'1'</span> AS Sum<span class="k2">;</span></span></p><pre>Result should be:
+-----+
| Sum | 
+-----+
|   2 | 
+-----+</pre><p>

That&#39;s why I ran away crying..........</p><p>I don&#39;t like that... Dynamic typing is evil...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 07:56:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It looks like get_role_users returns an array of classes or something, and array_unique has to be able to convert everything to strings. That&#39;s the only possible issue I can see with that code.</p><p>[edit]<br />Add a &#39;var_dump($teachers);exit(0);&#39; before the return, and paste what it prints.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 07:57:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[Reads PHP function]</p><p><i>{again runs away crying}</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 08:04:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The problem with trying to var_dump it, is it only works through AJAX <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> its quite hard to get it to pass in some error/debug crap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 08:07:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Then you could do:</p><pre>
file_put_contents(&#39;teacher.log&#39;, var_export($teachers));
</pre><p>

then post teacher.log.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 08:09:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><ul><li><p>Why define an $isTeacher variable and not use it?</p></li><li><p>What does get_my_courses() return?</p></li><li><p>What does get_context_instance() return?</p></li><li><p>What kind of variable name is $context?</p></li><li><p>What does get_role_users() return?</p></li><li><p>Why create two $myteacher[s] variables if the second isn&#39;t really used until you&#39;re done with the first?</p></li><li><p>Through all of the confusion this function brings me there are no comments!?</p></li></ul><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 08:13:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Its empty..</p><p>And the get_roles_user functions seem to get the roles in an array of something casted to (object)s.</p><p>bamccaig: this is not my code, please believe me ;(
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 08:15:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Thomas Fjellstrom said:</div><div class="quote"><p>
And the get_roles_user functions seem to get the roles in an array of something casted to (object)s.
</p></div></div><p>

The roles of what?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 08:16:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The roles of what?
</p></div></div><p>Of the user? Like if you&#39;re a teacher, or student, or lesbian, etc.</p><p>edit: actually thats not true...</p><p>They return other user objects that are assigned to that &quot;role&quot; (in this case, two forms of teacher).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 08:17:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
</p><ol><li><p>Why define an $isTeacher variable and not use it?
</p></li><li><p>What does get_my_courses() return?
</p></li><li><p>What does get_context_instance() return?
</p></li><li><p>What kind of variable name is $context?
</p></li><li><p>What does get_role_users() return?
</p></li><li><p>Why create two $myteacher[s] variables if the second isn&#39;t really used until you&#39;re done with the first?
</p></li><li><p>Through all of the confusion this function brings me there are no comments!?
</p></li></ol></div></div><p>

Don&#39;t ask him, he didn&#39;t write it. Nobody really knows what&#39;s going on. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Its empty..</p><p>And the get_roles_user functions seem to get the roles in an array of something casted to (object)s.
</p></div></div><p>

How could it be empty and still give those errors? This baffles me. What if you just try return $teachers; dropping the array_unique() call temporarily to see if it at least approaches how it is supposed to work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 08:18:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
Don&#39;t ask him, he didn&#39;t write it. Nobody really knows what&#39;s going on.
</p></div></div><p>

He has more information than I do... I&#39;m just trying to grasp what this function is supposed to do...</p><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
What if you just try return $teachers; dropping the array_unique() call temporarily to see if it at least approaches how it is supposed to work?
</p></div></div><p>

What if you rewrote the system, just to be sure.....?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 08:20:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What if you rewrote the site, just to be sure?
</p></div></div><p>I wish, It&#39;ll take less time to just find the last bits that are going haywire.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 08:21:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why rewrite code when you can fix it? The new code won&#39;t look much different, and that code at least did something at some point, so it&#39;s easier just to fix it, IMO.</p><p>Anyway, I&#39;m off to bed. I&#39;ll post more help in the morning.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Mar 2007 08:22:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
Why rewrite code when you can fix it? The new code won&#39;t look much different, and that code at least did something at some point, so it&#39;s easier just to fix it, IMO.
</p></div></div><p>

Have you ever heard of <a href="http://thedailywtf.com">The Daily WTF</a>, recently renamed <a href="http://worsethanfailure.com">Worse Than Failure</a>?</p><p>Everyday you&#39;ll find examples of how the code DIDN&#39;T work at some point (i.e. NEVER worked), and yet it&#39;s still part of an enterprise level system... If the guy that wrote that function had a lot to do with the site you might be better off rewriting it from scratch.</p><p>Patching it to work won&#39;t improve maintenance in the future. <s>It&#39;ll</s> <i>It might</i> speed up launch day (possibly implementing buggy code), but eventually maintenance might outweigh the benefits of keeping code now.</p><p>And I hope that the new code would look much different. <i>{smiley - when will EFW be over with!?!??!?}</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Mar 2007 08:26:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
eventually maintenance might outweigh the benefits of keeping code now.
</p></div></div><p>Won&#39;t be my problem. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Neither I or my friend will likely have anything more to do with the people that hired him/us.</p><p>I also don&#39;t know that much php, so uh, yeah...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 08:30:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I found out about thedailywtf from a.cc.  In fact, the majority of the sites I know now came as a reference from a.cc, like askaninja.com (which has apparently become really popular lately).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Fri, 30 Mar 2007 08:35:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
[Thu Mar 29 20:42:06 2007] [error] [client 192.168.1.20] PHP Catchable fatal error:<br />Object of class stdClass could not be converted to string in<br /><i>var/www/.../htdocs/chat/chat.php on line 345, referer: <a href="http://.../chat">http://.../chat</a></i>
</p></div></div><p>
I would bet that some MySQL result is trying to be used as an array index somewhere. Something like:
</p><div class="source-code snippet"><div class="inner"><pre>$foo <span class="k3">=</span> mysql_foo<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// returns an object</span>
$array<span class="k2">[</span>$foo<span class="k2">]</span> <span class="k3">=</span> <span class="s">'boom'</span><span class="k2">;</span>
</pre></div></div><p>
It tries to call $foo-&gt;__toString() and it doesn&#39;t exist, so something bad happens. From your code, I don&#39;t see why it would happen. But my instincts say that is the problem.</p><p>It&#39;s possible that &quot;mysql_foo()&quot; is returning some sort of error (as an object), instead of some expected value as a string. No error detection of course, so everything goes to hell.</p><p>For example:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">&lt;</span>?php
        $foo <span class="k3">=</span> <span class="k2">(</span>object<span class="k2">)</span><span class="s">'Error!'</span><span class="k2">;</span>
        $bar<span class="k2">[</span><span class="s">'test'</span>.$foo<span class="k2">]</span> <span class="k3">=</span> <span class="s">'Hello.'</span><span class="k2">;</span> <span class="c">// won't work</span>
?<span class="k3">&gt;</span>
</pre></div></div><p>
&quot;Catchable fatal error: Object of class stdClass could not be converted to string in foo.php on line 3&quot;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Fri, 30 Mar 2007 11:02:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll look into it. Though its a LOT of php code to dig thorough. All of the Moodle api, the bits of code done by the genius that coded the function above, and ADODB itself.</p><p>Is there a way to get php and ADODB to actually print out a backtrace like you get in C? I need to see the context of what was called from where. That ADODB error is absolutely useless since It makes me guess where it originated from.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Mar 2007 11:12:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could try throwing an Exception. I think that dumps out the function stack.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">throw</span> <span class="k1">new</span> Exception<span class="k2">(</span><span class="s">"foo"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

I also wouldn&#39;t mind taking a look at it via SSH. But that offer is only valid for the next few hours while I&#39;m waiting to get sleepy...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Fri, 30 Mar 2007 11:16:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure you want to... But ok. PM ahoyhoy.</p><p>edit:<br />Oh my, more problems:</p><pre>
[Fri Mar 30 17:32:17 2007] [error] [client 192.168.1.20] PHP Notice:
Trying to get property of non-object in /var/www/.../htdocs/chat/chat.php
on line 436, referer: <a href="http://.../chat/">http://.../chat/</a></pre><p>

here&#39;s the output from dumping $user:</p><div class="source-code snippet"><div class="inner"><pre>object<span class="k2">(</span>stdClass<span class="k2">)</span>#<span class="n">213</span> <span class="k2">(</span><span class="n">6</span><span class="k2">)</span> <span class="k2">{</span>
  <span class="k2">[</span><span class="s">"id"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  string<span class="k2">(</span><span class="n">1</span><span class="k2">)</span> <span class="s">"4"</span>
  <span class="k2">[</span><span class="s">"isteacher"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  string<span class="k2">(</span><span class="n">1</span><span class="k2">)</span> <span class="s">"1"</span>
  <span class="k2">[</span><span class="s">"isloggedin"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  string<span class="k2">(</span><span class="n">1</span><span class="k2">)</span> <span class="s">"1"</span>
  <span class="k2">[</span><span class="s">"logindate"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  string<span class="k2">(</span><span class="n">19</span><span class="k2">)</span> <span class="s">"2007-03-29 20:02:49"</span>
  <span class="k2">[</span><span class="s">"lastactivity"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  string<span class="k2">(</span><span class="n">19</span><span class="k2">)</span> <span class="s">"2007-03-29 20:02:49"</span>
  <span class="k2">[</span><span class="s">"temporary"</span><span class="k2">]</span><span class="k3">=</span><span class="k3">&gt;</span>
  NULL
<span class="k2">}</span>

<span class="k1">bool</span><span class="k2">(</span><span class="k1">false</span><span class="k2">)</span>
</pre></div></div><p>

And this is the line:<br /><span class="source-code"><span class="k1">if</span> <span class="k2">(</span>isset<span class="k2">(</span>$user<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> $user-&gt;isloggedin <span class="k3">=</span><span class="k3">=</span> <span class="s">"1"</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>  <span class="k2">(</span>isset<span class="k2">(</span>$user-&gt;lastactivity<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 31 Mar 2007 04:36:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The bool(false) would probably be from a second var_dump indicating the user isn&#39;t set. I&#39;d try this:</p><p><span class="source-code"><span class="k1">if</span> <span class="k2">(</span>isset<span class="k2">(</span>$user<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> $user <span class="k3">&amp;</span><span class="k3">&amp;</span> $user-&gt;isloggedin <span class="k3">=</span><span class="k3">=</span> <span class="s">"1"</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>  <span class="k2">(</span>isset<span class="k2">(</span>$user-&gt;lastactivity<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 31 Mar 2007 04:45:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Woot. That worked great, and eventually I got the stupid thing working. A nice little Ajax chat thing.</p><p>Now I&#39;m trying to mess with the css, but the css doesn&#39;t seem to be cascading. Or somehow Firefox is caching the css even when I clear the cache and restart <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> I look at the code with firebug, and nowhere does it see my modified items. Then again, konqueror won&#39;t notice them at all either <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /></p><p>Of course a lot of the stuff thats not changing is all generated in javascript.. Could that be the reason? I dunno, it sees the original css fine <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 31 Mar 2007 08:38:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
<span class="source-code"><span class="k1">if</span> <span class="k2">(</span>isset<span class="k2">(</span>$user<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> $user <span class="k3">&amp;</span><span class="k3">&amp;</span> $user-&gt;isloggedin <span class="k3">=</span><span class="k3">=</span> <span class="s">"1"</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>  <span class="k2">(</span>isset<span class="k2">(</span>$user-&gt;lastactivity<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></span>
</p></div></div><p>

The only time I&#39;ve ever had a use to check if a variable was set in PHP was when I was checking for GET and POST variables from a Web page. And when I did, I avoided the ugly use of isset() and just went straight to a boolean condition:</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">if</span><span class="k2">(</span>$_POST<span class="k2">[</span><span class="s">'btnSubmit'</span><span class="k2">]</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="c">// Do stuff</span>
    <span class="k2">}</span>
</pre></div></div><p>

Maybe there is something wrong or unreliable about doing that? It seems you had to check that anyway...</p><div class="source-code snippet"><div class="inner"><pre>    <span class="c">// Why bother checking isset($user)...</span>
    <span class="k1">if</span><span class="k2">(</span>isset<span class="k2">(</span>$user<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> ...<span class="k2">)</span>

    <span class="c">// If you have to also evaluate just $user...</span>
    <span class="k1">if</span><span class="k2">(</span>... <span class="k3">&amp;</span><span class="k3">&amp;</span> $user <span class="k3">&amp;</span><span class="k3">&amp;</span> ...<span class="k2">)</span>

    <span class="c">// Might this work instead?</span>
    <span class="k1">if</span><span class="k2">(</span>$user <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span><span class="k1">bool</span><span class="k2">)</span>$user-&gt;isloggedin <span class="k3">&amp;</span><span class="k3">&amp;</span> $user-&gt;lastactivity<span class="k2">)</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 03:13:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It might, but its working now, and cleaning up the code really isn&#39;t a priority. Whats left now are a few feature additions, and its out of my hands.</p><p>Thanks for the help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I still would like to figure out why the page is ignoring css changes, even with !important tagged on them. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 01 Apr 2007 03:29:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
// Why bother checking isset($user)...
</p></div></div><p>
Because it is a horrible programming practice to assume a variable exists when you don&#39;t know if it does. It triggers an E_NOTICE in PHP, which every responsible developer cares about.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 01 Apr 2007 03:35:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I agree. You should see the notices I get from the Syntax Highlighting plugin for mediawiki <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>edit: Clutter in the logs is a pain.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 01 Apr 2007 03:46:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
edit: Clutter in the logs is a pain.
</p></div></div><p>

Why is php logging to your log files? And why don&#39;t you use error_reporting(E_NONE);?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The only time I&#39;ve ever had a use to check if a variable was set in PHP was when I was checking for GET and POST variables from a Web page. And when I did, I avoided the ugly use of isset() and just went straight to a boolean condition:</p><p>    if($_POST[&#39;btnSubmit&#39;])<br />    {<br />        // Do stuff<br />    }
</p></div></div><p>

$_REQUEST works great for that. Also, as ML said, you shouldn&#39;t assume variables are set. Much better to just check if the variable isset().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sun, 01 Apr 2007 06:08:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why is php logging to your log files? And why don&#39;t you use error_reporting(E_NONE);?
</p></div></div><p>Because many php coders are inexperienced at best... Using error_reporting willy nilly in their source.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 01 Apr 2007 06:28:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
$_REQUEST works great for that. Also, as ML said, you shouldn&#39;t assume variables are set. Much better to just check if the variable isset().
</p></div></div><p>

I wasn&#39;t assuming the variables are set. I was checking them with a simple boolean condition. If the form wasn&#39;t submitted, for example, the following if statement&#39;s boolean condition would result in false and never execute:</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">if</span><span class="k2">(</span>$_POST<span class="k2">[</span><span class="s">'btnSubmit'</span><span class="k2">]</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="c">// Do stuff...</span>
    <span class="k2">}</span>
</pre></div></div><p>

Alternatively, if the form was submitted it should result in true and execute.</p><p>That might be bad example, being that I think the submit button only transmits as POST data if the button is pressed - at least I think that is true for ASP&#39;s Response.Form() (haven&#39;t done PHP in months). Alteratively, though, you should be able to check any field that doesn&#39;t result in 0 or empty (which would result in false). For example:</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">if</span><span class="k2">(</span>$_POST<span class="k2">[</span><span class="s">'txtUsername'</span><span class="k2">]</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> $_POST<span class="k2">[</span><span class="s">'pwdPassword'</span><span class="k2">]</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="c">// Query User table...</span>
    <span class="k2">}</span>
    <span class="k1">else</span>
    <span class="k2">{</span>
        <span class="c">// Handle bad login...</span>
    <span class="k2">}</span>
</pre></div></div><p>

I know about the $_REQUEST[] superglobal. The use of $_POST[] had nothing to do with what I was referring to. Besides, if your application wasn&#39;t designed to accept GET data there&#39;s really no point using $_REQUEST[].</p><p>In fact, the risk of name collisions is greater if you do use $_REQUEST[] than if you specify the transmission method.</p><p>It could also theoretically be easier to attempt malicious activity on your site if you use $_REQUEST because instead of creating a Web page (or using software) to transmit POST data to your site they can simply try appending to the query string...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 06:32:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why is php logging to your log files? And why don&#39;t you use error_reporting(E_NONE);?
</p></div></div><p>
Errors, warnings, and notices are good indicators that something is going wrong. Silently ignoring them doesn&#39;t make your code magically better. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If the form wasn&#39;t submitted, for example, the following if statement&#39;s boolean condition would result in false and never execute:
</p></div></div><p>
It would also trigger an E_NOTICE; thus it&#39;s a bad practice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 01 Apr 2007 06:37:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Unfortunately you get a warning if you access a array/hash index that doesn&#39;t exist. Mainly because you shouldn&#39;t be accessing undefined variables <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>In my perl code, I specifically use the most anal warning/error mode: <span class="source-code">use warnings<span class="k2">;</span> use strict<span class="k2">;</span></span><br />Which help cut out a lot of possible errors with using references, undefined variables, and whatnot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 01 Apr 2007 06:37:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
It would also trigger an E_NOTICE; thus it&#39;s a bad practice.
</p></div></div><p>

Which can be limited by only storing necessary data in session variables. On your live server you can limit error reporting to serious errors, excluding the maybes such as E_NOTICE that can occur during normal execution.</p><p>If it shouldn&#39;t be done that way then PHP shouldn&#39;t allow it. I agree it&#39;s not pretty, but then neither is isset(). Besides, what scripting language is pretty?</p><p>That&#39;s why I prefer programming in C++ to any kind of Web development. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p> <i>Today I attempted to test some PHP theory and realized that PHP isn&#39;t being processed by my Apache Web server... Now I have to figure out what&#39;s wrong and how to fix it. I was sure that I had run PHP scripts on this system before... Why not anymore!? :&#39;( To make it worse I&#39;ve been drinking Canadian beer so I&#39;m not at my best...</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 07:05:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I wasn&#39;t assuming the variables are set.
</p></div></div><p>

</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">if</span><span class="k2">(</span>$_POST<span class="k2">[</span><span class="s">'btnSubmit'</span><span class="k2">]</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="c">// Do stuff...</span>
    <span class="k2">}</span>
</pre></div></div><p>
</p></div></div><p>

Looks like an assumption to me. You are assuming $_POST[&#39;btnSubmit&#39;] is set and contains a boolean value. The proper solution here is to run it through isset. It will return true if the form was submitted, false otherwise (unless the button press was spoofed).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sun, 01 Apr 2007 08:24:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
Looks like an assumption to me. You are assuming $_POST[&#39;btnSubmit&#39;] is set and contains a boolean value. The proper solution here is to run it through isset. It will return true if the form was submitted, false otherwise (unless the button press was spoofed).
</p></div></div><p>

If $_POST[&#39;btnSubmit&#39;] isn&#39;t set it won&#39;t execute the if block. If it is set it will, unless maybe you set the value (the label) to an empty string or 0. Feel free to try it. I wrote a shopping cart project like that and it worked fine.</p><p>In other words, I&#39;m not assuming that $_POST[&#39;btnSubmit&#39;] is set. I&#39;m acknowledging that if it&#39;s not set the condition will fail. $_POST[&#39;btnSubmit&#39;] doesn&#39;t contain a boolean. It&#39;s been a while since I&#39;ve done PHP, but I believe it will contain either &#39;btnSubmit&#39; or whatever the value attribute was set to (&#39;Submit&#39;, for example)(btnSubmit was an &lt;input type=&quot;submit&quot; .../&gt;).</p><p>It may or may not require the error reporting to be configured lightly forgivingly in order to avoid displaying error messages on the page. If so, it&#39;s not really a problem since the errors displayed are more like &#39;maybe errors&#39; (not a problem) and for a live server you should have errors turned off anyway (users don&#39;t need to see PHP warnings/errors, and they shouldn&#39;t exist on your live system anyway, right? <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 10:23:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
In other words, I&#39;m not assuming that $_POST[&#39;btnSubmit&#39;] is set.
</p></div></div><p>
You are so! If it&#39;s not set, an E_NOTICE will be triggered. No one is saying that your assumption is changing the logic at all. However, your logs will be flooded with bogus E_NOTICEs, and you won&#39;t be able to spot when an E_NOTICE really is trouble. By using isset(), you avoid generating the E_NOTICE.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
users don&#39;t need to see PHP warnings/errors, and they shouldn&#39;t exist on your live system anyway, right?
</p></div></div><p>
You&#39;re absolutely right on the first half. Users shouldn&#39;t see the errors. The errors should go to log files.</p><p>You&#39;re partially right on the second half, but your conclusion is incorrect. Errors <i>shouldn&#39;t</i> occur on the live system, but if they do, you better be able to track it! By programming in such a way that all E_NOTICEs indicate problems, it&#39;s so much easier to debug problems. </p><p>Purposely writing code that triggers E_NOTICE is simply bad practice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 01 Apr 2007 10:44:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>** PREPEND **
</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
You are so!
</p></div></div><p>

I&#39;m not assuming that the variable is set. I&#39;m just using a non-standard way of checking it. If only PHP was properly installed on my Web server I would write some test scripts and reply with more confidence. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>** END PREPEND **
</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
You&#39;re partially right on the second half, but your conclusion is incorrect. Errors shouldn&#39;t occur on the live system, but if they do...
</p></div></div><p>

That&#39;s what the <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> was for. Geeez, a week of [semi-]emoticon freeness and people stop interpretting them.</p><p>There are obviously gonna be errors that slip through our VIGOROUS testing processes. However, more often than not they&#39;ll be logical errors anyway and an E_NOTICE in the log probably won&#39;t point you to those.</p><p>In any case, my argument is at a loss because I agree it&#39;s better to follow good practice, which in this case would have to be using isset(). I just find it such an ugly construct. I prefer compiler errors when a variable isn&#39;t declared. You know?</p><p>Maybe if there was a block of code near the top that checked for isset()s and handled missing variables right away. At least then it would group them together... Whatever. As I&#39;ve said in other threads, I&#39;m not a fan of Web development as it is today.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 11:10:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Purposely writing code that triggers E_NOTICE is simply bad practice.
</p></div></div><p>Oh man did I learn that with perl. Perl lets you do things in almost any way imaginable. More complex scripts can get down right confusing, even for a perl maniac, and without &quot;use strict&quot; strict type checking isn&#39;t enabled and all sorts of very &quot;interesting&quot; things are possible, like mixing undefined stuff, all types of symbol references that should almost never happen, and things along those lines.</p><p>Its the same reason I use -W -Wall with GCC, and make sure all warnings are gone. I don&#39;t need them getting in the way of finding an actual problem.</p><p>Theres a reason warnings exist, to tell you you&#39;re doing something WRONG. It may not be a fatal error by default, but its still an error, wether you like it or not.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I just find it such an ugly construct.
</p></div></div><div class="source-code snippet"><div class="inner"><pre><span class="p"># perl:</span>
<span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>defined $var<span class="k2">)</span> <span class="k2">{</span> ... <span class="k2">}</span>
... <span class="k1">if</span> <span class="k3">!</span>defined $var<span class="k2">;</span>
</pre></div></div><p>
Which is worse do you think?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 01 Apr 2007 11:10:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Thomas Fjellstrom said:</div><div class="quote"><p>
Which is worse do you think?
</p></div></div><p>

I&#39;d say they&#39;re about the same, but I might actually prefer the defined/!defined syntax. Maybe not. Scripting languages are just evil to begin with. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>** APPEND **</p><p>I can honestly say that in my little PHP writing that I&#39;ve done I&#39;ve never relied on a log to tell me where my errors are. I plan my script and test it extensively to be sure it&#39;s working as I intended.</p><p>What are some examples of hard to notice logic errors that will trigger E_NOTICEs?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 01 Apr 2007 11:14:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m not assuming that the variable is set. I&#39;m just using a non-standard way of checking it. If only PHP was properly installed on my Web server I would write some test scripts and reply with more confidence. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div></div><p>

So you&#39;re telling me that I can do the following in C++ to see if a variable exists:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>myMagicBitmap<span class="k2">)</span>
<span class="k2">{</span>
    oh it <a href="http://www.allegro.cc/manual/exists" target="_blank"><span class="a">exists</span></a><span class="k3">!</span>
<span class="k2">}</span>
</pre></div></div><p>

I think not. You ARE assuming it exists. You explicitly reference it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sun, 01 Apr 2007 19:27:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What are some examples of hard to notice logic errors that will trigger E_NOTICEs?
</p></div></div><p>
Typos, logic that prevents a variable from being defined, unexpected index values...</p><p>It gets more useful as the project becomes more complex. For simple one-off scripts, it&#39;s not that big of a deal. But when you&#39;re creating an entire framework/library of code, then it&#39;s very useful. (Especially when you forget how you did things...)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 01 Apr 2007 20:29:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
So you&#39;re telling me that I can do the following in C++ to see if a variable exists...
</p></div></div><p>

PHP is in no way C++! Besides, the compiler will tell you if a variable doesn&#39;t &#39;exist&#39; in C++ so, to my knowledge, you shouldn&#39;t need to check if one does exist...</p><p>BAF, have you even programmed a script in PHP!?</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
Typos, logic that prevents a variable from being defined, unexpected index values...
</p></div></div><p>

If you misspell a variable you should quickly see that the intended action isn&#39;t happening correctly (during testing) and can use print() statements to trace the execution path.</p><p>In terms of logic that prevents a variable from being defined, this can be almost eliminated by declaring your variables at the top of your script, functions, and methods. Which is also a best practice...</p><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Again, I guess I agree that you should use isset(), but I still don&#39;t like it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Mon, 02 Apr 2007 00:30:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
BAF, have you even programmed a script in PHP!?
</p></div></div><p>

Resisting... urge...... to be..... smartass...........</p><p>I have done a LOT of PHP work. Once upon a (short) time I was pretty naive like you. Then I learned the importance of writing clean code.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If you misspell a variable you should quickly see that the intended action isn&#39;t happening correctly (during testing) and can use print() statements to trace the execution path.</p><p>In terms of logic that prevents a variable from being defined, this can be almost eliminated by declaring your variables at the top of your script, functions, and methods. Which is also a best practice...</p><p>Again, I guess I agree that you should use isset(), but I still don&#39;t like it.
</p></div></div><p>

You may not notice a variable issue like that if it&#39;s in an obscure not-well-used code path. The notices really do help save a lot of time. IF you ever start writing important code, you will (I hope..) learn the importance of clean code and the easy way of debugging. You don&#39;t need to predefine all your variables at the top, but you definately shouldn&#39;t assume stuff like post variables exist. That is just foolish. Also, isset() makes your code more readable.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Mon, 02 Apr 2007 00:33:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
You don&#39;t need to predefine all your variables at the top, but you definately shouldn&#39;t assume stuff like post variables exist.
</p></div></div><p>

You don&#39;t need to, but you should. And I never assumed it was set. Scripting langauges like PHP are funny in that if the variable doesn&#39;t exist it will evaluate it as false and therefore in a boolean condition can be treated like a flag. If it was set it would evaluate to true. If it&#39;s not set (doesn&#39;t exist) is will evaluate to false, similar to null.</p><p>I&#39;ve seen isset() code and I say it&#39;s less readable. It all depends. There may be circumstances where my way won&#39;t work, but in the even of checking form fields that cannot be zero or empty it works fine. To make it more readable you could easy create a hidden form field to check instead of the button:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>...etc</td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="k3">&lt;</span>?php</td></tr><tr><td class="number">4</td><td>    <span class="k1">if</span><span class="k2">(</span>$_POST<span class="k2">[</span><span class="s">'hidSubmitted'</span><span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">5</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">6</td><td>        <span class="c">// Form was submitted...</span></td></tr><tr><td class="number">7</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">8</td><td>?<span class="k3">&gt;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>...etc...</td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>    <span class="k3">&lt;</span>form ...<span class="k3">&gt;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>...etc...</td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>        <span class="k3">&lt;</span>input type<span class="k3">=</span><span class="s">"hidden"</span> name<span class="k3">=</span><span class="s">"hidSubmitted"</span> id<span class="k3">=</span><span class="s">"hidSubmitted"</span> value<span class="k3">=</span><span class="s">"true"</span> <span class="k3">/</span><span class="k3">&gt;</span></td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td>...etc...</td></tr><tr><td class="number">19</td><td>&#160;</td></tr><tr><td class="number">20</td><td>    <span class="k3">&lt;</span><span class="k3">/</span>form&gt;</td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td>etc...</td></tr></tbody></table></div></div><p>

I do write clean code. I&#39;m more obsessive about it than most. It all depends on what you call clean.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Wed, 04 Apr 2007 18:32:21 +0000</pubDate>
	</item>
</rss>
