# Declare directive to change engine version basis

- Thread: https://staging.externals.io/message/96997
- Original archive: https://news-web.php.net/php.internals/96997
- Started by David Rodrigues on 2016-11-18T16:18:07+00:00
- Messages: 3
- RFC: Deprecations for PHP 7.2 (Implemented (PHP 7.2)) — https://staging.externals.io/rfc/deprecations_php_7_2.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #96997 — David Rodrigues — 2016-11-18T16:18:07+00:00

URL: https://staging.externals.io/message/96997#96997

Hello.

I like to propose a creation of a new declare() directive that allows
"emulates a future engine version". And where I say engine I mean PHP
itself.

-

It should works like it (eg. for engine version "7.0.13"):

    declare( {{parameter}} = {{php_version_id}} );

    // Examples (one of that):
    declare( engine_version = 70013 ); // or
    declare( php_version = 70013 );

-

By default, this declaration is not defined (null or 0), then will not
do anything to engine if it's not declared on script.

-

This declaration could be done at:

    - First execution file.php (bootstrap): then all application will
follow this engine rules;
    - Any file.php: then only current file will follow this rules (to
override locally first declaration);
    - php.ini: to set this declaration as default to all applications
(optional);

-

What it does: in pratical, if the engine will deprecated or change
something on future versions (mainly causing BCs), you should wait for
a new major version (eg. 7.x -> 8.x). With this declaration you could
emulates a future version to prepares your scripts to a new major
version.

-

Let working on an example from: https://wiki.php.net/rfc/deprecations_php_7_2

The (unset) cast should not be used anymore because it's have not any
effect (just return null, but not affect the expression or variable).
Let supposed that this deprecation is done at 7.2.0 (id 70200), then
if I'm using this version and I declare engine_version like:

    - no declared or null: just a deprecation notice;
    - declare as 70200 or higher: error, (unset) cast doesn't exists
(or something like that)

-

Then, what the engine_version does is set some variable to engine that
could check if it could be executed on declared version, then
developers can code their files to future versions without need wait
for it.

-

If the installed version is different of declared version, then the
engine will always consider the lowest version between both. For
instance: if installed version is 70201 (7.2.1) and declared version
is 70205 (7.2.5), then engine will consider changes from 70201 (7.2.1,
once that installed is lower). And again: engine will works
differently only if declaration is done, else, it'll works by
deprecation notice, for instance.

-

What happen on engine code is something like that (pseudo-code):

    int engine_version () {
        return (int) engine_version_declaration;
    }

    cast type unset () {
        if (engine_version() >= 70201) {
            fatal(cast doesn't supported);
        }

        notice(deprecated);
        return null;
    }


-- 
David Rodrigues

---

## #96999 — Daniel Morris — 2016-11-18T18:01:25+00:00

URL: https://staging.externals.io/message/96997#96999 · In reply to: #96997

I think this would create a lot of additional work for internals
maintainers, and the current system of throwing an `E_DEPRECATED` already
allows for developers to prepare their applications for future versions
by turning on error reporting and checking their logs.

--
Daniel Morris
daniel@honestempire.com

---

## #97000 — Stephen Reay — 2016-11-18T18:05:30+00:00

URL: https://staging.externals.io/message/96997#97000 · In reply to: #96997

Hi David,

If you wanted to do this, couldn’t you simply use the following, already:

set_error_handler(
	function (int $err_severity, string $err_msg, string $err_file, int $err_line, array $err_context) {
		throw new ErrorException($err_msg, 0, $err_severity, $err_file, $err_line)
	},
 `E_DEPRECATED` 
);

?

> 
> 
> Hello.
> 
> I like to propose a creation of a new declare() directive that allows
> "emulates a future engine version". And where I say engine I mean PHP
> itself.
> 
> -
> 
> It should works like it (eg. for engine version "7.0.13"):
> 
>    declare( {{parameter}} = {{php_version_id}} );
> 
>    // Examples (one of that):
>    declare( engine_version = 70013 ); // or
>    declare( php_version = 70013 );
> 
> -
> 
> By default, this declaration is not defined (null or 0), then will not
> do anything to engine if it's not declared on script.
> 
> -
> 
> This declaration could be done at:
> 
>    - First execution file.php (bootstrap): then all application will
> follow this engine rules;
>    - Any file.php: then only current file will follow this rules (to
> override locally first declaration);
>    - php.ini: to set this declaration as default to all applications
> (optional);
> 
> -
> 
> What it does: in pratical, if the engine will deprecated or change
> something on future versions (mainly causing BCs), you should wait for
> a new major version (eg. 7.x -> 8.x). With this declaration you could
> emulates a future version to prepares your scripts to a new major
> version.
> 
> -
> 
> Let working on an example from: https://wiki.php.net/rfc/deprecations_php_7_2
> 
> The (unset) cast should not be used anymore because it's have not any
> effect (just return null, but not affect the expression or variable).
> Let supposed that this deprecation is done at 7.2.0 (id 70200), then
> if I'm using this version and I declare engine_version like:
> 
>    - no declared or null: just a deprecation notice;
>    - declare as 70200 or higher: error, (unset) cast doesn't exists
> (or something like that)
> 
> -
> 
> Then, what the engine_version does is set some variable to engine that
> could check if it could be executed on declared version, then
> developers can code their files to future versions without need wait
> for it.
> 
> -
> 
> If the installed version is different of declared version, then the
> engine will always consider the lowest version between both. For
> instance: if installed version is 70201 (7.2.1) and declared version
> is 70205 (7.2.5), then engine will consider changes from 70201 (7.2.1,
> once that installed is lower). And again: engine will works
> differently only if declaration is done, else, it'll works by
> deprecation notice, for instance.
> 
> -
> 
> What happen on engine code is something like that (pseudo-code):
> 
>    int engine_version () {
>        return (int) engine_version_declaration;
>    }
> 
>    cast type unset () {
>        if (engine_version() >= 70201) {
>            fatal(cast doesn't supported);
>        }
> 
>        notice(deprecated);
>        return null;
>    }
> 
> 
> -- 
> David Rodrigues
