equal to perls "strict" 
Author Message
 equal to perls "strict"

Hi there

Is there an command that equals to the perl "strict" statement?

 - Johan



Sun, 22 May 2005 01:16:20 GMT  
 equal to perls "strict"

Quote:
> Is there an command that equals to the perl "strict" statement?

What functionality of 'strict' are you looking for?

I use strict in Perl to throw errors at me when
I use package variables instead of lexical 'my' variables.

php does not distinguish between the two - it is totally
lexically scoped.  Php doesn't have 'packages' or 'modules'.

So what are you looking for?

regards,
reggie.



Sun, 22 May 2005 01:35:01 GMT  
 equal to perls "strict"

Quote:

> I use strict in perl to keep an eye on me and make sure I dont fall
> into sloppy programming practices. strict makes you declare variables
> and makes you do thing correctly whereas without strict a script can
> run with sloppy and thus possibly unsafe code.

Well error_reporting(E_ALL) will generate warnings whenever you use
undeclared variables.

Andr N?ss



Sun, 22 May 2005 03:24:38 GMT  
 equal to perls "strict"

Quote:

> >What functionality of 'strict' are you looking for?

> >I use strict in Perl to throw errors at me when
> >I use package variables instead of lexical 'my' variables.

> I use strict in perl to keep an eye on me and make sure
> I dont fall into sloppy programming practices.

Strict only covers a very small percentage
of sloppy programing practices.

Quote:
> strict makes you declare variables

Not entirely correct.
It stops you from using unqualified package variables.

eg.)
for ($i=1; $i<2; $i++) print $i;

This would generate a strict warning because
I am trying to use the package variable
'$i' without a valid package qualifier
($main::i or whatever)

As programmers usually want to use lexical variables and not
package variables, it can remind the programmer to force lexical
scoping using the 'my' operator

for (my $i; $i<2; $i++) print $i;

or to use the full path to the package variable
(probably not wanted):

# this is equivalent to the _first_ for decleration
# running without the stric pragma - but no warning
for ($main::i; $main::i<2; $main::i) print $i;

or allow its use through 'import', 'use' or 'our'

Quote:
> and makes you do thing correctly

No - it forces you to make sure your
doing things in a certain way.

Quote:
> whereas without strict a script can
> run with sloppy and thus possibly unsafe code.

No - sloppy code is a result of not knowing what one is doing,
or why one is doing it.

Quote:
> strict is like a very strict boss leaning over your shoulder :)

I am being pedantic, and this is all
about Perl and nothing about php so I'll just
point you to Perl Documentation.

If you program in Perl enough, you _should_ know this.

http://perldoc.com/perl5.8.0/lib/strict.html

What you are talking about is 'strict vars'.  Read about it.
Then read about the difference between 'my' vs. 'local' and
'dynamic scoping' vs. 'lexical scoping'

Again - what strict _really_ does cannot be done in php because
php lexically scopes everything.  There are no package variables.

regards,
reggie.



Sun, 22 May 2005 04:10:13 GMT  
 equal to perls "strict"

Quote:
> >I am being pedantic, and this is all

> No your being a git

Actually, it seems I am both.

Offline messaging with Tony has woken me to
the fact that I misunderstood his original intention in posting.

apologies to Tony for any implications my post had.

regards,
reggie.



Sun, 22 May 2005 06:09:21 GMT  
 equal to perls "strict"

Quote:

>>Offline messaging with Tony has woken me to
>>the fact that I misunderstood his original intention in posting.

>>apologies to Tony for any implications my post had.

> I think we both went off in he wrong direction at some point... hands
> shook and all is well :)

What *was* the original intent then?

Just curious...



Sun, 22 May 2005 07:19:31 GMT  
 equal to perls "strict"

Quote:


>>>>Offline messaging with Tony has woken me to
>>>>the fact that I misunderstood his original intention in posting.

>>What *was* the original intent then?

> My original intention was to *add* to reggies post by adding another
> use for strict. ie: my reason for using it.

> This looked like I was arguing its use rather than adding to it and
> Usenet being usenet it quickly snowballed. However as two {*filter*}s we
> have figured out what went wrong (Missunderstanding and me probably
> not being clear enough) and all is well.

Fair enough!  The whole discussion made me think about how to catch
sloppy code in PHP - it has no use strict; , it can't give you warnings
like c can, all in all, it's not very helpful!  error_reporting(E_ALL)
is all I have to go on - it would be nice to have a strict option.


Sun, 22 May 2005 08:18:29 GMT  
 equal to perls "strict"
Yes.  Put the following at the top of your PHP file:

error_reporting(E_ALL);

Quote:

> Hi there

> Is there an command that equals to the perl "strict" statement?

>  - Johan



Sun, 22 May 2005 11:38:09 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Perl like "strict"?

2. "EQUAL?" and Circular structures

3. overloading "=" (equal sign)

4. Problem with "IS EQUAL TO"

5. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

6. How can I distinguish "equal" events in Java procedure "processEvent()"?

7. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

8. Parsing ""D""?

9. "Fifth", "Forth", zai nar?

10. Ruby "finalize", "__del__"

11. beginners "let"/"random" question

12. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

 

 
Powered by phpBB® Forum Software