Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
use strict

Posted by John_Moylan (John_Moylan), 17 July 2002
Well after using PHP for the past month my biggest gripe is the lack of 'use strict'.

This pragma has been a godsend in Perl, surely it's got to come soon to PHP.

Or am I the only one who thinks this?

jfp


Posted by admin (Graham Ellis), 18 July 2002
Both Perl and PHP have "grown up" from languages in which programmers wrote relativly short utility scripts into languages in which major applications are written. This forum is a good example - it happens to be written in Perl (yes, I know I'm posting on the PHP board!), but that's not the origins.  Recall that PHP was originally "Personal Home Pages", and Perl is the "Practical Extraction and reporting language".  Neither of these imply big applications.

When writing a shorter piece of code, having to declare variables adds code which isn't really necessary.  It takes time to type in all those "int" or "float", "my" or "our" words and ensure that they're all present, and for what real gain?  As your application gets longer, so variable declaration does have a point - it ensures that you don't have a "typo" somewhere in your code that is hard to find during testing and it helps in the "selfdocumentation" of something that's going to take more reading / understanding than a little utility.

PHP does not (as far as I know) have an equivalent of "use strict".  You can use the error_reporting function to help you catch variables that you have not initialised in your code; see the online manual at

http://www.php.net/manual/en/function.error-reporting.php

Here's an example of it in use:

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

Graham



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

Comment: "I agree with John. The bulk of time is spent on design and ..."
Visitor Ranking 4.0 (5=excellent, 1=poor)

Comment by Rutishauser (published 2010-07-15)
I agree with John. The bulk of time is spent on design and debugging, rather than on pressing keys on the keyboard. So, no matter what you are writing, a big complicated program or a couple of simple lines, strict typification is certainly of great help. [#3629]

You can Add a comment or ranking or edit your own comments

Average page ranking - 4.0

© WELL HOUSE CONSULTANTS LTD., 2019: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho