php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18214 Request: strict mode option in PHP
Submitted: 2002-07-07 17:38 UTC Modified: 2002-07-09 07:00 UTC
Votes:6
Avg. Score:2.8 ± 1.9
Reproduced:2 of 3 (66.7%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: djanix at hotmail dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4CVS-2002-07-07 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: djanix at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-07-07 17:38 UTC] djanix at hotmail dot com
  just a quick feature request...

  how about a warning for assignment inside of an expression, like most c compilers will generate...

  " if ( $a = false ) { "

  would generate a warning... if u had the warning enabled of course.... 

  i'm surprised it doesn't already do that...

  -benjamin+

  

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-07 17:40 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
 [2002-07-07 17:41 UTC] sniper@php.net
Not possible: if ($xx = some_function()) {} is perfectly
legal.

 [2002-07-07 17:55 UTC] djanix at hotmail dot com
right it's legal - but it's so rare that it is usually a mistake, which is why most c compilers will generate a warning for it.  would have saved me a good 30 minutes tonight spent searching for the cause of a bug... :(

  -benjamin
 [2002-07-07 18:18 UTC] jan@php.net
on a side note, it is a good practice to swap the 'assignment arguments':
if ('foo' == $bar), since 'foo' = $bar does produce a warning.


 [2002-07-08 10:19 UTC] m dot ford at lmu dot ac dot uk
Rare???  What do you mean, rare???

Nearly every script I write uses this construct multiple times.  Sometimes, it occurs more often than equality comparisons.  Changing this would make my life hell!!

Cheers!

Mike
 [2002-07-09 02:09 UTC] philip@php.net
What are some other potential "strict" mode watches?  Some  people ask for an optional "strict" mode with various options, this could be a good start?  Imagine a strict mode directive where when on, various options could be set at runtime, like assignment_inside_expression = true :)
 [2002-07-09 04:58 UTC] tal@php.net
IMHO, this behavior shhould not be implemented.
This construct is used widely actually (almost in every script i've ever written).
And usually warnings imply that something is wrong, while there is nothing wrong with that.

-Tal
 [2002-07-09 06:04 UTC] philip@php.net
Nobody is wanting this to be a core feature (I would think not even error_reporting(E_ALL) would turn on strict mode) but rather part of an optional strict mode directive in PHP.  AFAICT, most php-dev people are against a strict mode option altogether, and this feature request is only part of that.  I, along with you and many others, love to do assignments in expressions.  The minority wanting a mode similar to perls "use strict" or VBscripts "option explicit" or a C compiler or whatever, want optional options like this one.  These people would/should understand what their getting into by enabling strict mode.  BTW, I did not mean assignment_inside_expression to be a directive in php.ini but rather an option for, let's say,  set_strict_mode_options().

I've searched archives and couldn't find the arguments against having this mode available but obviously some exist.  Like, how PHP is simply not a strict language so deal with it.  Or how adding an optional directive like this will confuse some people and cause headaches.  Or how difficult and resource intensive such a change might be. *shrug*  This may need to be a faq.  Changing topic to be more generic.

Related requests: #14285, #14405.
 [2002-07-09 06:21 UTC] hholzgra@php.net
sidenote:  c compilers that warn on
  
   if ( a = b )

usualy accept

   if ( ( a = b ) )

so only top level assignments are considert harmfull

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 08:01:28 2024 UTC