[RFC] -W option for CLI "strict mode"

php.internals

Adam Harvey

15 years ago
Developers, Romans, countrymen, I'd like to propose the addition of a -W switch to the CLI SAPI which would enable the display of errors and maximum error reporting. This brings us into line with other languages such as Perl, and allows us to evangelise to users that they should run "php -W script.php" as the preferred way of developing and running new, E_STRICT-compliant scripts. The RFC is at https://wiki.php.net/rfc/cli-strict, and comes with a patch, which is accessible at http://www.adamharvey.name/patches/php-cli-strict.patch.txt. If the response isn't overwhelmingly negative and we don't get caught up in discussions for the next few days, I'll look at calling for a vote in a week or so (given it's not a language-level change). Thanks, Adam

Richard Quadling

15 years ago
On 5 July 2011 16:33, Adam Harvey <aharvey@php.net> wrote:
> Developers, Romans, countrymen, > > I'd like to propose the addition of a -W switch to the CLI SAPI which > would enable the display of errors and maximum error reporting. This > brings us into line with other languages such as Perl, and allows us > to evangelise to users that they should run "php -W script.php" as the > preferred way of developing and running new, E_STRICT-compliant > scripts. > > The RFC is at https://wiki.php.net/rfc/cli-strict, and comes with a > patch, which is accessible at > http://www.adamharvey.name/patches/php-cli-strict.patch.txt. If the > response isn't overwhelmingly negative and we don't get caught up in > discussions for the next few days, I'll look at calling for a vote in > a week or so (given it's not a language-level change). > > Thanks, > > Adam
Bikesheding thought ... -V, --verbose That could get interesting ... C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose Non bikeshedding thought ... Being able to enable full error reporting at the command line has to be complimented though by fully disabling error reporting ... -Q, --quiet or -S, --silent Question, ... When does the ini file get read and processed in regards to the command line params? Richard.
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Adam Harvey

15 years ago
On 5 July 2011 23:50, Richard Quadling <rquadling@gmail.com> wrote:
> Bikesheding thought ... > > -V, --verbose > > That could get interesting ... > > C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose
I like matching other languages as best we can (more on that in my reply to Felipe momentarily).
> Non bikeshedding thought ... > > Being able to enable full error reporting at the command line has to > be complimented though by fully disabling error reporting ... > > -Q, --quiet or -S, --silent
Pierre made the same suggestion. It would be easy enough to implement, obviously; I'll put a v1.1 patch up with that included.
> Question, ... > > When does the ini file get read and processed in regards to the > command line params?
Before the command line parameters are parsed. Adam

Richard Quadling

15 years ago
On 5 July 2011 17:22, Adam Harvey <aharvey@php.net> wrote:
> On 5 July 2011 23:50, Richard Quadling <rquadling@gmail.com> wrote: >> Non bikeshedding thought ... >> >> Being able to enable full error reporting at the command line has to >> be complimented though by fully disabling error reporting ... >> >> -Q, --quiet or -S, --silent > > Pierre made the same suggestion. It would be easy enough to implement, > obviously; I'll put a v1.1 patch up with that included.
I'd also add in the display_startup_errors to this also. As I see it, the idea is to make things as noisy or as quiet as possible.
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Adam Harvey

15 years ago
On 6 July 2011 06:00, Richard Quadling <rquadling@gmail.com> wrote:
> I'd also add in the display_startup_errors to this also. As I see it, > the idea is to make things as noisy or as quiet as possible.
Agreed. That was an oversight on my part. I'll update the patches to handle that as well. Adam

Michael Robinson

15 years ago
On July-06-11 12:58 AM Adam Harvey wrote:
> On 6 July 2011 06:00, Richard Quadling <rquadling@gmail.com> wrote: > > I'd also add in the display_startup_errors to this also. As I see it, > > the idea is to make things as noisy or as quiet as possible. > > Agreed. That was an oversight on my part. I'll update the patches to > handle that as well.
Nice. I have use for this. Best Regards, Mike Robinson

Richard Quadling

15 years ago
On 6 July 2011 15:14, Mike Robinson <mike@rile.ca> wrote:
> On July-06-11 12:58 AM Adam Harvey wrote: > > >> On 6 July 2011 06:00, Richard Quadling <rquadling@gmail.com> wrote: >> > I'd also add in the display_startup_errors to this also. As I see it, >> > the idea is to make things as noisy or as quiet as possible. >> >> Agreed. That was an oversight on my part. I'll update the patches to >> handle that as well. > > Nice. > > I have use for this. > > Best Regards, > > Mike Robinson > >
What happens of both LOUD and quiet are used. Personally, I'd say this is an error and abort.
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Peter Cowburn

15 years ago
On 6 July 2011 16:04, Richard Quadling <rquadling@gmail.com> wrote:
> On 6 July 2011 15:14, Mike Robinson <mike@rile.ca> wrote: >> On July-06-11 12:58 AM Adam Harvey wrote: >> >> >>> On 6 July 2011 06:00, Richard Quadling <rquadling@gmail.com> wrote: >>> > I'd also add in the display_startup_errors to this also. As I see it, >>> > the idea is to make things as noisy or as quiet as possible. >>> >>> Agreed. That was an oversight on my part. I'll update the patches to >>> handle that as well. >> >> Nice. >> >> I have use for this. >> >> Best Regards, >> >> Mike Robinson >> >> > > What happens of both LOUD and quiet are used. Personally, I'd say this > is an error and abort.
An error, and abort silently. :)

Michael Robinson

15 years ago
On July-06-11 11:49 AM Peter Cowburn [mailto:petercowburn@gmail.com]
> On 6 July 2011 16:04, Richard Quadling <rquadling@gmail.com> wrote: > > > > What happens of both LOUD and quiet are used. Personally, I'd say > > this is an error and abort. > > > > An error, and abort silently. :)
Whatever the consensus is. :) The devil's in the details of course (and that's easy for me to say since I'm not doing the work). But overall I'd say this is a nice, simple, useful feature. Best Regards, Mike Robinson

Johannes Schlueter

15 years ago
On Tue, 2011-07-05 at 16:50 +0100, Richard Quadling wrote:
> C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose
That happens with all options. $ php -n run-tests.php -n
> Non bikeshedding thought ... > > Being able to enable full error reporting at the command line has to > be complimented though by fully disabling error reporting ... > > -Q, --quiet or -S, --silent
What would happen with logging then? Will that be switched off, too? johannes

Richard Quadling

15 years ago
2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> On Tue, 2011-07-05 at 16:50 +0100, Richard Quadling wrote: >> C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose > > That happens with all options. >   $ php -n run-tests.php -n >
You missed out the -- That separates arguments from php.exe and the script. As long as one remembers that, they should be OK.
>> Non bikeshedding thought ... >> >> Being able to enable full error reporting at the command line has to >> be complimented though by fully disabling error reporting ... >> >> -Q, --quiet or -S, --silent > > What would happen with logging then? Will that be switched off, too?
If error_reporting() is set to 0, what errors can be generated?
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Johannes Schlueter

15 years ago
On Wed, 2011-07-06 at 16:46 +0100, Richard Quadling wrote:
> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>: > > On Tue, 2011-07-05 at 16:50 +0100, Richard Quadling wrote: > >> C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose > > > > That happens with all options. > > $ php -n run-tests.php -n > > > > You missed out the -- > > That separates arguments from php.exe and the script. > > As long as one remembers that, they should be OK.
This is not needed usually: $ cat t.php <?php print_r($argv); $ php -n t.php -n Array ( [0] => t.php [1] => -n )
> >> Non bikeshedding thought ... > >> > >> Being able to enable full error reporting at the command line has to > >> be complimented though by fully disabling error reporting ... > >> > >> -Q, --quiet or -S, --silent > > > > What would happen with logging then? Will that be switched off, too? > > If error_reporting() is set to 0, what errors can be generated?
Well that's exactly the question: Is that expected or is it just supposed to be silent on the console only? (same for -W btw.) johannes

Richard Quadling

15 years ago
2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> On Wed, 2011-07-06 at 16:46 +0100, Richard Quadling wrote: >> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>: >> > On Tue, 2011-07-05 at 16:50 +0100, Richard Quadling wrote: >> >> C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose >> > >> > That happens with all options. >> >   $ php -n run-tests.php -n >> > >> >> You missed out the -- >> >> That separates arguments from php.exe and the script. >> >> As long as one remembers that, they should be OK. > > This is not needed usually: > > $ cat t.php > <?php > print_r($argv); > > > $ php -n t.php -n > Array > ( >    [0] => t.php >    [1] => -n > )
On windows ...
>copy con C:\t.php
<?php print_r($argv); ^Z 1 file(s) copied.
>php -v
PHP 5.3.7RC3-dev (cli) (built: Jul 4 2011 14:05:17) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
>C:\PHP5\php.exe -n -f C:\t.php -n
Array ( [0] => C:\t.php )
>C:\PHP5\php.exe -n -f C:\t.php -- -n
Array ( [0] => C:\t.php [1] => -n ) php --help specifically shows this too.
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Richard Quadling

15 years ago
2011/7/7 Richard Quadling <rquadling@gmail.com>:
> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>: >> On Wed, 2011-07-06 at 16:46 +0100, Richard Quadling wrote: >>> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>: >>> > On Tue, 2011-07-05 at 16:50 +0100, Richard Quadling wrote: >>> >> C:\php5\php.exe --verbose -f d:\docs\phd\render.php -- --verbose >>> > >>> > That happens with all options. >>> >   $ php -n run-tests.php -n >>> > >>> >>> You missed out the -- >>> >>> That separates arguments from php.exe and the script. >>> >>> As long as one remembers that, they should be OK. >> >> This is not needed usually: >> >> $ cat t.php >> <?php >> print_r($argv); >> >> >> $ php -n t.php -n >> Array >> ( >>    [0] => t.php >>    [1] => -n >> ) > > On windows ... > >>copy con C:\t.php > <?php > print_r($argv); > ^Z >        1 file(s) copied. > >>php -v > PHP 5.3.7RC3-dev (cli) (built: Jul  4 2011 14:05:17) > Copyright (c) 1997-2011 The PHP Group > Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies > > >>C:\PHP5\php.exe -n -f C:\t.php -n > Array > ( >    [0] => C:\t.php > ) > >>C:\PHP5\php.exe -n -f C:\t.php -- -n > Array > ( >    [0] => C:\t.php >    [1] => -n > ) > > > php --help specifically shows this too.
Aha!
>C:\PHP5\php.exe -n C:\t.php -n -- -j
Array ( [0] => C:\t.php [1] => -n [2] => -- [3] => -j ) Without -f, all arguments after the script name belong to the script. Without -f, argument order becomes important.
-- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

Felipe Nascimento Silva Pena

15 years ago
Hi, 2011/7/5 Adam Harvey <aharvey@php.net>:
> Developers, Romans, countrymen, > > I'd like to propose the addition of a -W switch to the CLI SAPI which > would enable the display of errors and maximum error reporting. This > brings us into line with other languages such as Perl, and allows us > to evangelise to users that they should run "php -W script.php" as the > preferred way of developing and running new, E_STRICT-compliant > scripts. > > The RFC is at https://wiki.php.net/rfc/cli-strict, and comes with a > patch, which is accessible at > http://www.adamharvey.name/patches/php-cli-strict.patch.txt. If the > response isn't overwhelmingly negative and we don't get caught up in > discussions for the next few days, I'll look at calling for a vote in > a week or so (given it's not a language-level change). > > Thanks, > > Adam > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Just to inform, the Perl's -W enable all warnings regardless of whether the script disable warnings. The Perl's -w one looks like your -W, but I know we already have used -w in PHP to output source with stripped comments and whitespaces. However I guess it's more useful to have something like Perl does with -W.
-- Regards, Felipe Pena

Adam Harvey

15 years ago
On 6 July 2011 00:01, Felipe Pena <felipensp@gmail.com> wrote:
> Just to inform, the Perl's -W enable all warnings regardless of > whether the script disable warnings. > > The Perl's -w one looks like your -W, but I know we already have used > -w in PHP to output source with stripped comments and whitespaces.
That was basically why I chose -W (since it was as close as I could get).
> However I guess it's more useful to have something like Perl does with -W.
It does really combine -w and -W from Perl, now I think about it. Adam

Florian Anderiasch

15 years ago
On 05.07.2011 18:24, Adam Harvey wrote:
>> However I guess it's more useful to have something like Perl does with -W. > > It does really combine -w and -W from Perl, now I think about it.
What would be the options of mimicking -W as closely as possible? There was this extension (iirc named scream and by Johannes) that unsilenced @calls. Would this fit into as well? I suppose some kind of monkeypatching error_reporting/ini_set/whatIforgot to ignore all settings in the script(s) would be anything from bad style to downright impossible, but maybe someone has a brilliant idea to enhance this. Greetings, Florian

Adam Harvey

15 years ago
On 6 July 2011 05:08, Florian Anderiasch <florian@anderiasch.de> wrote:
> On 05.07.2011 18:24, Adam Harvey wrote: >>> However I guess it's more useful to have something like Perl does with -W. >> >> It does really combine -w and -W from Perl, now I think about it. > > What would be the options of mimicking -W as closely as possible? > > There was this extension (iirc named scream and by Johannes) that > unsilenced @calls. Would this fit into as well?
The idea of integrating scream was raised on IRC as well. But...
> I suppose some kind of monkeypatching > error_reporting/ini_set/whatIforgot to ignore all settings in the > script(s) would be anything from bad style to downright impossible, but > maybe someone has a brilliant idea to enhance this.
It's probably possible, but in general, I'm not sure we should be tinkering with explicitly set settings and suppression within scripts. Setting good defaults for development is one thing, but the script writer should probably have the final say. Adam