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

- Thread: https://externals.io/message/53745
- Original archive: https://news-web.php.net/php.internals/53745
- Started by Adam Harvey on 2011-07-05T15:33:01+00:00
- Messages: 18
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #53745 — Adam Harvey — 2011-07-05T15:33:01+00:00

URL: https://externals.io/message/53745#53745

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

---

## #53746 — Richard Quadling — 2011-07-05T15:50:21+00:00

URL: https://externals.io/message/53745#53746 · In reply to: #53745

> 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

---

## #53747 — Felipe Pena — 2011-07-05T16:01:52+00:00

URL: https://externals.io/message/53745#53747 · In reply to: #53745

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
>
> --
> 
> 
>

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

---

## #53749 — Adam Harvey — 2011-07-05T16:22:20+00:00

URL: https://externals.io/message/53745#53749 · In reply to: #53746

> 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

---

## #53748 — Adam Harvey — 2011-07-05T16:24:22+00:00

URL: https://externals.io/message/53745#53748 · In reply to: #53747

> 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

---

## #53751 — Florian Anderiasch — 2011-07-05T21:08:12+00:00

URL: https://externals.io/message/53745#53751 · In reply to: #53748

> > […]
> 
> 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

---

## #53752 — Richard Quadling — 2011-07-05T22:00:02+00:00

URL: https://externals.io/message/53745#53752 · In reply to: #53749

> 
> > […]
>
> 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

---

## #53754 — Adam Harvey — 2011-07-06T04:58:13+00:00

URL: https://externals.io/message/53745#53754 · In reply to: #53752

> 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

---

## #53753 — Adam Harvey — 2011-07-06T05:02:26+00:00

URL: https://externals.io/message/53745#53753 · In reply to: #53751

> 
> > […]
>
> 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

---

## #53761 — Mike Robinson — 2011-07-06T14:14:26+00:00

URL: https://externals.io/message/53745#53761 · In reply to: #53754

On July-06-11 12:58 AM Adam Harvey wrote:


> 
> > […]
> 
> 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

---

## #53762 — Richard Quadling — 2011-07-06T15:04:25+00:00

URL: https://externals.io/message/53745#53762 · In reply to: #53761

> On July-06-11 12:58 AM Adam Harvey wrote:
>
>
> > […]
>
> 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

---

## #53763 — johannes@schlueters.de — 2011-07-06T15:40:32+00:00

URL: https://externals.io/message/53745#53763 · In reply to: #53746

> 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

---

## #53764 — Richard Quadling — 2011-07-06T15:46:07+00:00

URL: https://externals.io/message/53745#53764 · In reply to: #53763

2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> 
> > […]
>
> 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.


> > […]
>
> 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

---

## #53765 — Peter Cowburn — 2011-07-06T15:48:39+00:00

URL: https://externals.io/message/53745#53765 · In reply to: #53762

> 
> > […]
>
> What happens of both LOUD and quiet are used. Personally, I'd say this
> is an error and abort.

An error, and abort silently. :)

>
>
> --
> Richard Quadling
> Twitter : EE : Zend : PHPDoc
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

---

## #53766 — johannes@schlueters.de — 2011-07-06T16:00:41+00:00

URL: https://externals.io/message/53745#53766 · In reply to: #53764

> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> > […]
> 
> 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
)


> > […]
> 
> 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

---

## #53767 — Mike Robinson — 2011-07-06T16:33:48+00:00

URL: https://externals.io/message/53745#53767 · In reply to: #53765

On July-06-11 11:49 AM Peter Cowburn [mailto:petercowburn@gmail.com]
 
> 
> > […]
> 
> 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

---

## #53769 — Richard Quadling — 2011-07-07T15:16:49+00:00

URL: https://externals.io/message/53745#53769 · In reply to: #53766

2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> 
> > […]
>
> 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

---

## #53770 — Richard Quadling — 2011-07-07T15:19:30+00:00

URL: https://externals.io/message/53745#53770 · In reply to: #53769

2011/7/7 Richard Quadling <rquadling@gmail.com>:
> 2011/7/6 Johannes Schlüter <johannes@schlueters.de>:
> > […]
>
> On windows ...
>
> > […]
> <?php
> print_r($argv);
> ^Z
>        1 file(s) copied.
>
> > […]
> 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
>
>
> > […]
> Array
> (
>    [0] => C:\t.php
> )
>
> > […]
> 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
