Fog Creek Software
Discussion Board




How To Get Rich Programming Error

Joel, if you want to talk about PHP, you REALLY ought to RTFM once in awhile.

In your recent article "How To Get Rich Programming" which appeared in The Programmers Paradise Catalog (and presumably elsewhere) you state:

"PHP will never catch a misspelled variable because variables don't have to be declared..."

This is patently false.

PHP issues a "notice" for each and every variable used, but not initialized, and has done so since at LEAST version 3.

These warnings are, by default, suppresed in php.ini using the error_reporting setting.

You can reset error_reporting to E_ALL in php.ini, or in .htaccess, or by using the error_reporting function.

References:
http://php.net/error_reporting

Richard Lynch
Monday, December 08, 2003

I can't find it with google, a link please?

Alex
Monday, December 08, 2003

The problem is that it isn't on by default, and that it isn't *obviously* configurable.

T-bone
Monday, December 08, 2003

Joe Bob Programmer, if you want to talk about Xyz, you REALLY ought to RTFM once in awhile.

[insert completely reasonable 'mistake' here]

This is patently false.

Xyz has done the opposite since at LEAST version 3.

This feature is, by default, suppresed.

You can reset the feature by changing feature_9 to $6_Goo in the config file.

DUH.

jevus
Monday, December 08, 2003

That problem could be quoted for any language without an IDE. This includes lots of C compilers, Perl, PHP, and most scripting languages. Nothing about any of these is 'obviously' configurable. Most obvious configuration requires a visual interface, which these languages don't have. Configuration utilities are outside of the scope of language projects and are normally left to integrated tool developers, allowing language designers to focus on technical issues.

Also, turning these on by default is not a design mistake, just a design decision. In scripting languages such as PHP, it is usually a decent assumption that variable declaration causes excess baggage. This is because most of the development is for simple - medium complexity sites and the languages are targeted at being usable for a wider range of audiences.

Dustin Alexander
Monday, December 08, 2003

With perl you just put a "use strict;" declaration at the top of your code, likewise in ASP classic you put "Option Explicit" at the top.

Matthew Lock
Monday, December 08, 2003

This does not, to me, obviously configurable make. It requires language knowledge. Which does not, however, detract from my original statement :)

Dustin Alexander
Monday, December 08, 2003

Assemble the above words into a well known phrase or sentence. (20 marks).

Simon Lucy
Monday, December 08, 2003

So uh ... how do you get rich by programming?

bye
Monday, December 08, 2003

bye - I think you have to hack into a bank. Note that I am not recommending it, just answering your question.


Tuesday, December 09, 2003

By stealing a penny from every bank transaction!

Alyosha`
Tuesday, December 09, 2003

>>
PHP issues a "notice" for each and every variable used, but not initialized, and has done so since at LEAST version 3.
<<

There is a huge difference between initializing a variable and declaring a variable. 

As far as I know, PHP has no way of separately declaring a variable so there is no way for it to detect an undeclared variable.  Is "$fooo = 5" an assignment or initialization?  If you intended to type "$foo = 5" to assign to an existing variable named $foo, how would PHP detect that error? 

In VB, a variable can be declared using Dim so "Dim foo" followed by "fooo = 5" will produce an error (with Option Explicit).

SomeBody
Tuesday, December 09, 2003

I always liked "Dim sum" personally.

Richard P
Tuesday, December 09, 2003

"By stealing a penny from every bank transaction!"

Well, it's not really stealing if those fractions of a cent were just going to go nowhere anyway.  It's more like salvage in that situation.  ;)

Norrick
Tuesday, December 09, 2003

Hm...

--------------------------------
<html><body>
<?php
$aI = 1;
while ($aI < 100) {
    echo "This is a test...<br>";
    $al = $al+1;
}
?></body></html>
---------------------------------

No warning, no error, nothing. Not the best of examples, but it shows a point. I _hate_ PHP for this and for it's strange concept of "scope".

Leonardo Herrera
Wednesday, December 10, 2003

Ah, even more patently false statements.

Here are some FACTS to contradtict them:

There are web-GUI interfaces to the php.ini file, if that makes you feel better than using the built-in, well-documented, well-designed function error_reporting.

Reference:
The Zend Launch Pad ($$$) has one.  I'm sure there are others, many are free, but this was the first example to come to mind.  Anybody can download the free demo and verify my statement.

You can Google for "PHP variable misspell warning" and find many many many on-line suggestions to use error_reporting.  This was simply my first try to find documentation.  Presumably other reasonable search terms will find similar documentation.
Reference:
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=PHP+variable+misspell+warning&btnG=Google+Search

And Leonardo, you are just plain WRONG:

Here is the output of your script on my server:
Reference:
http://l-i-e.com/notice.php

I did take the liberty of explicitly adding error_reporting(E_ALL) at the top, so others can more easily replicate this proof.  I also added an exit; inside the loop, since I don't really want your code wasting my CPU cycles.
Reference:
http://l-i-e.com/notice.phps

Oh, and anybody who uses $aI as a variable name should be shot. :-)

That last was an OPINION, not a FACT.

Richard Lynch
Wednesday, December 10, 2003

Here's a slightly modified version of Leonardo's code:

--------------------------------
<html><body>
<?php
$aI = 1;
while ($aI < 100) {
    echo "This is a test...<br>";
    $al = $aI+1;
}
?></body></html>
--------------------------------

Do you get an error with that?

SomeBody
Wednesday, December 10, 2003

*  Recent Topics

*  Fog Creek Home