hi,
could you please write down few use cases, when strict scalar type hints
are really useful.
Thanks. Dmitry.
Hi Dmitry,
It's preferred to have flexible scalars, that way we can interchange
between a numerical string or an integer.
Over defining on such things loses the powerfulness of PHP. So scalar
typehints are detrimental rather than useful. Saying something is a scalar
or not, is useful however! :)
A use case would be where scalar type hints are detrimental are:
I implement an API that returns integers for entity ids, like 2,3,4,5,6.
and my web-frontend handles this fine because it's a scalar. Then, you want
to convert entity ids to UUID. This would break your entire web frontend
application since it's no longer "integer" whereas the concept of $id is
good enough.
Did this make sense?
TL;DR - I am against such proposals.
Many thanks,
Paul
hi,
could you please write down few use cases, when strict scalar type hints
are really useful.Thanks. Dmitry.
A use case would be where scalar type hints are detrimental are:
I implement an API that returns integers for entity ids, like 2,3,4,5,6.
and my web-frontend handles this fine because it's a scalar. Then, you want
to convert entity ids to UUID. This would break your entire web frontend
application since it's no longer "integer" whereas the concept of $id is
good enough.
Others are of the opinion that the type of the value is an important
detail that should be managed by something other than automatic
conversion.
I'm going to be fairly busy with work for the next few days but I'll
try to remember to come back and give a few good examples I have for
strict values.
Hi Dmitry,
It's preferred to have flexible scalars, that way we can interchange
between a numerical string or an integer.Over defining on such things loses the powerfulness of PHP. So scalar
typehints are detrimental rather than useful. Saying something is a scalar
or not, is useful however! :)A use case would be where scalar type hints are detrimental are:
I implement an API that returns integers for entity ids, like 2,3,4,5,6.
and my web-frontend handles this fine because it's a scalar. Then, you want
to convert entity ids to UUID. This would break your entire web frontend
application since it's no longer "integer" whereas the concept of $id is
good enough.
I don't think this is a good case where strict type hinting is really
helpful.
Did this make sense?
TL;DR - I am against such proposals.
Now, I'm more interested in opinions of people who like strict type hinting.
I prefer weak hints, that follow standard conversion rules, but may be good
arguments may change my mind.
Thanks. Dmitry.
Many thanks,
Paulhi,
could you please write down few use cases, when strict scalar type hints
are really useful.Thanks. Dmitry.
hi,
hi,
could you please write down few use cases, when strict scalar type hints
are really useful.
I think there is one big misunderstanding in Andrea's RFC.
Strictness is local only. Or to say it in a better way, only the
maintainers of a given library will bother with it. Users of this
library do not, there will be no change there from what we had in the
1st rfc. Or they can if they want.
Keeping that in mind, the declare statement, as ugly as it may look,
could be actually a killer to finally get what both camps want but
never (and never will) manage to agree.
--
Pierre
@pierrejoye | http://www.libgd.org
hi,
hi,
could you please write down few use cases, when strict scalar type hints
are really useful.I think there is one big misunderstanding in Andrea's RFC.
Strictness is local only. Or to say it in a better way, only the
maintainers of a given library will bother with it.
Actually, not.
The proposal makes declare() work on caller side.
So, each usage of a library function in user code may be wrapped with
declare() or not.
Thanks. Dmitry.
Users of this
library do not, there will be no change there from what we had in the
1st rfc. Or they can if they want.Keeping that in mind, the declare statement, as ugly as it may look,
could be actually a killer to finally get what both camps want but
never (and never will) manage to agree.
--
Pierre@pierrejoye | http://www.libgd.org
Hi!
Keeping that in mind, the declare statement, as ugly as it may look,
could be actually a killer to finally get what both camps want but
never (and never will) manage to agree.
I think having two conceptual frameworks in one language and having to
deal with (and potentially maintain) code bases with mixed conceptual
framework is a very bad idea. That would lead to a language
fragmentation as strict code will become hard to combine with non-strict
code within one application, and pretty soon people will start asking
questions like "is this library written in strict-PHP or non-strict-PHP?
ow, dang, we can't use it because we use the other one..."
Stas Malyshev
smalyshev@gmail.com
Hi Stas,
Hi!
Keeping that in mind, the declare statement, as ugly as it may look,
could be actually a killer to finally get what both camps want but
never (and never will) manage to agree.I think having two conceptual frameworks in one language and having to
deal with (and potentially maintain) code bases with mixed conceptual
framework is a very bad idea. That would lead to a language
fragmentation as strict code will become hard to combine with non-strict
code within one application, and pretty soon people will start asking
questions like "is this library written in strict-PHP or non-strict-PHP?
ow, dang, we can't use it because we use the other one…"
I don’t see how. This proposal has been specifically designed to allow strict and non-strict code to be completely interoperable.
--
Andrea Faulds
http://ajf.me/
Hi!
Keeping that in mind, the declare statement, as ugly as it may look,
could be actually a killer to finally get what both camps want but
never (and never will) manage to agree.I think having two conceptual frameworks in one language and having to
deal with (and potentially maintain) code bases with mixed conceptual
framework is a very bad idea. That would lead to a language
fragmentation as strict code will become hard to combine with non-strict
code within one application, and pretty soon people will start asking
questions like "is this library written in strict-PHP or non-strict-PHP?
ow, dang, we can't use it because we use the other one..."
Stas, I respectfully think you misunderstand the RFC.
I think one good way to make a parallel is to compare it to having
error_reporting(0); or error_reporting(E_ALL); on top of every file.
The RFC as it stands would make type hints be silently coerced by
default, so it would have "error reporting" disabled by default, but if
you set the declare line you do the equivalent of enabling error
reporting but only for your calls and returns.
Right now if you use a sloppy library for example that throws E_STRICT,
and you have reporting enabled, you do have fragmentation and it sucks,
for example:
// strict.php
include 'non-strict.php';
error_reporting(E_ALL);
foo();
// non-strict.php
error_reporting(0);
function foo() {
echo UNDEFINED_CONSTANT_FTW;
}
foo();
This produces:
UNDEFINED_CONSTANT_FTW
Notice: Use of undefined constant UNDEFINED_CONSTANT_FTW - assumed
'UNDEFINED_CONSTANT_FTW' in non-strict.php on line 5
UNDEFINED_CONSTANT_FTW
In this case the strict file by using a non-strict function gets
warnings thrown, so the community has to encourage/force everyone to
behave strictly in libraries otherwise their code does not integrate well.
On the other hand, with the type hints, every file chooses how they want
to behave and since it is not an ini setting it can not be influenced by
another file like in my example above. Consider this for example:
// strict.php
declare(strict_types=1);
include 'non-strict.php';
foo(10);
// non-strict.php
include 'strict2.php';
function foo(string $output) {
echo $output.PHP_EOL;
}
foo(5);
strictFoo(5);
// strict2.php
declare(strict_types=1);
function strictFoo(string $output) {
echo $output.PHP_EOL;
}
This results in:
5 // output of foo from non-strict context
5 // output of strictFoo from non-strict context
Catchable fatal error: foo() expects parameter 1 to be string, integer
given // failure of foo from strict context
So we see that the non-strict code works just fine on it's own, 5 gets
coerced to string, no matter if it's calling strict libraries or
non-strict ones, since it is itself non-strict. The strictness of others
does not influence non-strict code and everyone integrates very well
together.
When strict code calls non-strict code, they get errors if they pass
invalid params, but that is what they want since they asked to be
strict, so they get full on error reporting/static analysis of their
code, but do not push it on the whole ecosystem.
Cheers
--
Jordi Boggiano
@seldaek - http://nelm.io/jordi
Hi Dimitry,
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 10:13
An: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: [PHP-DEV] What do we need strict scalar type hints for?hi,
could you please write down few use cases, when strict scalar type hints are really useful.
Thanks. Dmitry.
I think strict types are beneficial in all those places where you would put manual tests to ensure that the passed value is of a certain type and only of this type - removing the hassle (ok, I did not add anything to the discussion so far ^^). Right now, I mainly think of functions which expect an int - especially in the domain of time and money. I would expect an int and I would not want that a float can be passed without warning and get silently converted to an int (loosing precision in the domain of time or money can be crucial).
However, IMO it is not necessary to have a strict mode as presented by Andrea -- I think it would be good enough if we use the same widening rules as in Java, C# etc. and be strict otherwise. I am aware of that with the support of BigInteger we would have a widening problem (BigInteger to float) but could be solved by a BigDecimal as in Clojure.
Ah... I now something I would definitely want to be strict. I guess a typical bug, which is made by many beginners, is using the result of strpos in an if statement without using the identity operator -- btw. would the strict mode affect operators and control structures as well? Would somehow be the logical consequence but I suppose the impact on performance would be too big. Or wouldn't it?
Back to the topic, if I expect a bool as parameter I would definitely not want it to be automatically converted since this is a sink for bugs.
Hope that helps.
Cheers,
Robert
Hi Dimitry,
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 10:13
An: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: [PHP-DEV] What do we need strict scalar type hints for?hi,
could you please write down few use cases, when strict scalar type hints
are really useful.Thanks. Dmitry.
I think strict types are beneficial in all those places where you would
put manual tests to ensure that the passed value is of a certain type and
only of this type - removing the hassle (ok, I did not add anything to the
discussion so far ^^). Right now, I mainly think of functions which expect
an int - especially in the domain of time and money. I would expect an int
and I would not want that a float can be passed without warning and get
silently converted to an int (loosing precision in the domain of time or
money can be crucial).
However, IMO it is not necessary to have a strict mode as presented by
Andrea -- I think it would be good enough if we use the same widening rules
as in Java, C# etc. and be strict otherwise. I am aware of that with the
support of BigInteger we would have a widening problem (BigInteger to
float) but could be solved by a BigDecimal as in Clojure.Ah... I now something I would definitely want to be strict. I guess a
typical bug, which is made by many beginners, is using the result of strpos
in an if statement without using the identity operator -- btw. would the
strict mode affect operators and control structures as well?
no. now we speak only about parameter and return value type hints.
Would somehow be the logical consequence but I suppose the impact on
performance would be too big. Or wouldn't it?
it wouldn't reduce performance. may be even increase, but it'll break every
second app.
Back to the topic, if I expect a bool as parameter I would definitely not
want it to be automatically converted since this is a sink for bugs.
I'm not sure. If we would work on a type-safe language I would definitely
agree, but PHP is a "loosely typed language" by definition.
Thanks. Dmitry.
Hope that helps.
Cheers,
Robert
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 20:14
An: Robert Stoll
Cc: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for?Hi Dimitry,
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 10:13
An: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: [PHP-DEV] What do we need strict scalar type hints for?hi,
could you please write down few use cases, when strict scalar type
hints
are really useful.Thanks. Dmitry.
I think strict types are beneficial in all those places where you
would put manual tests to ensure that the passed value is of a certain
type and only of this type - removing the hassle (ok, I did not add
anything to the discussion so far ^^). Right now, I mainly think of
functions which expect an int - especially in the domain of time and
money. I would expect an int and I would not want that a float can be
passed without warning and get silently converted to an int (loosing
precision in the domain of time or money can be crucial).However, IMO it is not necessary to have a strict mode as presented by
Andrea -- I think it would be good enough if we use the same widening
rules as in Java, C# etc. and be strict otherwise. I am aware of that
with the support of BigInteger we would have a widening problem
(BigInteger to
float) but could be solved by a BigDecimal as in Clojure.Ah... I now something I would definitely want to be strict. I guess a
typical bug, which is made by many beginners, is using the result of
strpos in an if statement without using the identity operator -- btw.
would the strict mode affect operators and control structures as well?no. now we speak only about parameter and return value type hints.
[Robert Stoll]
Could be addressed in another RFC then.
Would somehow be the logical consequence but I suppose the impact on
performance would be too big. Or wouldn't it?it wouldn't reduce performance. may be even increase, but it'll break every second app.
[Robert Stoll]
I wrote it a little bit ambiguously, I actually meant a negative big impact on performance. Concerning the second part of your sentence. As other already mentioned, it would not break every second app since only those apps would be concerned which enable the strict mode and even then only those files are concerned which are written by the owner of the code and the owner oneself decided to use the strict mode, ergo => everything is fine as long as the owner writes strict code and if she/he does not, then it actually must break since the owner of the file made a mistake in terms of strictness and wished to be informed about it. Makes sense no?
Back to the topic, if I expect a bool as parameter I would definitely
not want it to be automatically converted since this is a sink for bugs.I'm not sure. If we would work on a type-safe language I would definitely agree, but PHP is a "loosely typed language" by
definition.
[Robert Stoll]
I agree, PHP is weakly typed and that is fine. Yet, if we are discussing what strict types would be useful for then the mentioned examples are good use cases IMO.
Personally, I think weak type hints as suggested in the RFC might be a way to go for PHP [*] where in a type-safe version of PHP (such as TSPHP [1]) it would not make sense at all.
[*] even though I think it is really ugly that a float or a float in a string can be passed to a function expecting an int. IMO only those values should automatically converted where it can be guaranteed that no precision is lost. Maybe I have not read the RFC carefully enough - following some examples to illustrate what I mean:
function foo(int $i){}
foo(1); //ok
foo(2.0); //still fine
foo("2"); //acceptable as well
foo('3.0'); //even this is ok
foo(1.4); //ouch
foo("1.2"); //please no
foo("1lxs"); //oh no.. please... noooo ^^
Well, yeah... I guess you get my point.
[1] http://tsphp.ch
Thanks. Dmitry.
Hope that helps.
Cheers,
Robert--
To unsubscribe,
visit: http://www.php.net/unsub.php
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 20:14
An: Robert Stoll
Cc: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for?Hi Dimitry,
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Montag, 2. Februar 2015 10:13
An: PHP Internals; Andrea Faulds; Nikita Popov
Betreff: [PHP-DEV] What do we need strict scalar type hints for?hi,
could you please write down few use cases, when strict scalar type
hints
are really useful.Thanks. Dmitry.
I think strict types are beneficial in all those places where you
would put manual tests to ensure that the passed value is of a certain
type and only of this type - removing the hassle (ok, I did not add
anything to the discussion so far ^^). Right now, I mainly think of
functions which expect an int - especially in the domain of time and
money. I would expect an int and I would not want that a float can be
passed without warning and get silently converted to an int (loosing
precision in the domain of time or money can be crucial).However, IMO it is not necessary to have a strict mode as presented by
Andrea -- I think it would be good enough if we use the same widening
rules as in Java, C# etc. and be strict otherwise. I am aware of that
with the support of BigInteger we would have a widening problem
(BigInteger to
float) but could be solved by a BigDecimal as in Clojure.Ah... I now something I would definitely want to be strict. I guess a
typical bug, which is made by many beginners, is using the result of
strpos in an if statement without using the identity operator -- btw.
would the strict mode affect operators and control structures as well?no. now we speak only about parameter and return value type hints.
[Robert Stoll]
Could be addressed in another RFC then.Would somehow be the logical consequence but I suppose the impact on
performance would be too big. Or wouldn't it?it wouldn't reduce performance. may be even increase, but it'll break
every second app.[Robert Stoll]
I wrote it a little bit ambiguously, I actually meant a negative big
impact on performance. Concerning the second part of your sentence. As
other already mentioned, it would not break every second app since only
those apps would be concerned which enable the strict mode and even then
only those files are concerned which are written by the owner of the code
and the owner oneself decided to use the strict mode, ergo => everything is
fine as long as the owner writes strict code and if she/he does not, then
it actually must break since the owner of the file made a mistake in terms
of strictness and wished to be informed about it. Makes sense no?
I don't think we will implement strict semantic for operators.
It's not going to be PHP anymore....
$s = (string)$a . (string)$b;
Back to the topic, if I expect a bool as parameter I would definitely
not want it to be automatically converted since this is a sink for
bugs.I'm not sure. If we would work on a type-safe language I would
definitely agree, but PHP is a "loosely typed language" by
definition.[Robert Stoll]
I agree, PHP is weakly typed and that is fine. Yet, if we are discussing
what strict types would be useful for then the mentioned examples are good
use cases IMO.
Personally, I think weak type hints as suggested in the RFC might be a
way to go for PHP [*] where in a type-safe version of PHP (such as TSPHP
[1]) it would not make sense at all.[*] even though I think it is really ugly that a float or a float in a
string can be passed to a function expecting an int. IMO only those values
should automatically converted where it can be guaranteed that no precision
is lost. Maybe I have not read the RFC carefully enough - following some
examples to illustrate what I mean:function foo(int $i){}
foo(1); //ok
foo(2.0); //still fine
foo("2"); //acceptable as well
foo('3.0'); //even this is okfoo(1.4); //ouch
foo("1.2"); //please no
foo("1lxs"); //oh no.. please... noooo ^^Well, yeah... I guess you get my point.
Yes. But this not about strict vs weak. This is about conversion rules,
that we may change in a more cosistent way.
Thanks. Dmitry.
[1] http://tsphp.ch
Thanks. Dmitry.
Hope that helps.
Cheers,
Robert--
To unsubscribe,
visit: http://www.php.net/unsub.php
Hi Dmitry,
I don't think we will implement strict semantic for operators.
It's not going to be PHP anymore....
$s = (string)$a . (string)$b;
There’s no need either: operators always produce a specific type (or one of a set of types) so it doesn’t really cause a problem.
Though there are some improvements we could make. It’d be nice if ‘’ + 1 produced a notice, that’s caught me out several times before.
Thanks.
--
Andrea Faulds
http://ajf.me/
could you please write down few use cases, when strict scalar type hints
are really useful.
Do we NEED strict scalar type control ... No
Are there situations where strict scalar type control may be useful ...Yes
Can a library be built ONLY using strict scalar type control ... Maybe
... provided that it only requires a set of data that can be 'strict'
Much has been made of the idea that automatically causing errors when a
wrong scalar type has been passed will simplify things, and in some
cases that may be true, A few examples have been thrown up which suggest
that integer values are a magic bullet when dealing with time or
currency for example, but only some elements of that can easily be
constrained to integers, other parts will require float or even string.
When there is an error in any of this would one not expect any good
library to produce a sensible set of error messages? A generic 'value
not integer' needs to be augmented, so error checking against those
elements that may be constrained would be mixed with error checking with
the more weakly typed elements anyway?
I can see that for some cases there may be an advantage but would it not
be better to provide something that can act as a validity check against
any input rather than some limited set of data? One 'class' that can
identify where a scalar can be constrained or give a more relaxed result
when required ... rather than having one rule for one and one for the other?
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
-----Ursprüngliche Nachricht-----
Von: Lester Caine [mailto:lester@lsces.co.uk]
Gesendet: Montag, 2. Februar 2015 21:06
An: internals@lists.php.net
Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for?could you please write down few use cases, when strict scalar type
hints are really useful.Do we NEED strict scalar type control ... No Are there situations where strict scalar type control may be useful ...Yes Can a
library be built ONLY using strict scalar type control ... Maybe ... provided that it only requires a set of data that can be 'strict'Much has been made of the idea that automatically causing errors when a wrong scalar type has been passed will simplify
things, and in some cases that may be true, A few examples have been thrown up which suggest that integer values are a
magic bullet when dealing with time or currency for example, but only some elements of that can easily be constrained to
integers, other parts will require float or even string.
When there is an error in any of this would one not expect any good library to produce a sensible set of error messages? A
generic 'value not integer' needs to be augmented, so error checking against those elements that may be constrained
would be mixed with error checking with the more weakly typed elements anyway?I can see that for some cases there may be an advantage but would it not be better to provide something that can act as a
validity check against any input rather than some limited set of data? One 'class' that can identify where a scalar can be
constrained or give a more relaxed result when required ... rather than having one rule for one and one for the other?--
Lester Caine - G8HFL
Nobody would stop you from implementing a utility class Money or likewise and providing a better error message instead of using int if PHP would be strict only (what is not proposed in the RFC anyway). You could also just omit the type hint, it is entirely up to you.
There are plenty of strongly typed languages out there which work very well without the mentioned lack of specific error messages for each individual use case.
And btw. PHP is strict for array and class type hints as well - of course you can also omit those type hints.
Nobody would stop you from implementing a utility class Money or likewise and providing a better error message instead of using int if PHP would be strict only (what is not proposed in the RFC anyway). You could also just omit the type hint, it is entirely up to you.
The point here was that this is creating yet another set of rules that
only apply in some cases. Rather than perhaps looking at a more generic
solution that can be used in validation across all types.
There are plenty of strongly typed languages out there which work very well without the mentioned lack of specific error messages for each individual use case.
Lived with that in the past ... having to convert everything TO some
common type before using it is just as irritating. PHP's lighter touch
especially where data is coming in mainly from a string based feed is
much nicer to work with.
And btw. PHP is strict for array and class type hints as well - of course you can also omit those type hints.
Which are creating even more conflicts.
The ONE element that I am growing concerned about is a simple 64bit
BIGINT primary key which can be used as an array index. A strict integer
is heading towards some complex variable length data type, while for
probably 99.9% of database related BIGINT data it is a simple integer.
If third party libraries move towards a 'strict' style of working they
may not be efficient when used without that practice, or they may not
play nicely with other interfaces that have a different 'strict' view.
There are a growing number of low cost devices which are essentially 32
bit devices, but with 64 bit maths which is possibly incompatible with
the current 'strict' view of data within PHP.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
2015-02-02 11:12 GMT+02:00 Dmitry Stogov dmitry@zend.com:
hi,
could you please write down few use cases, when strict scalar type hints
are really useful.Thanks. Dmitry.
Hello Dmitry,
At the moment, being a user-land dev for a little bit more than 10 years, I
just don't see the usage for the strict type hints at the moment. I just
can't imagine it actually being usefull for the masses. Yes, some deep core
library code may use them, wrapped in layers and layers of code, so deep,
that it actually works.
But on a day to day basis? No-no-no-no-noooo. I'll probably mess it all up
quite fast and end up just stripping those away. It's quite a foreign
concept for me for the PHP code (not that I haven't written in strict typed
languages, but I had to define all the variables up front in the program).
On a day to day basis I juggle a lot data back and forth - parsing an XML
document comes to mind immedeatly (because I have tons of them, with all
kinds of data), i handle a lot of JSON data (including input, that is
mostly strings, because it comes from forms in text form), memcached is
other example. CVS files. And so on. It's the little everyday stuff that
after years just feels natural to do that will be affected and cause grief,
and these days many liek to jump on the hype train without any regard for
the others.
So, for me, the first step is to get the "converting", "Weak" or whatever
you call them, type hints into the language. And I have a perfect case of
"why" for it.
Just look back at how OOP arrived into PHP and how it evolved.
PHP 4 (yeah, I remember some from those days still) was very basic, and for
me that was a very short phase.
Them came PHP 5 with it's more serious OOP aproach and features. And in 10
years look what has become of the OOP feature set? And all of it really
fits. It started with the basics and ended-up in a very good state. And
most additions that came along had time to be understood and solidify
before more was added. People eased in into it naturally and many changed
their views on the subject with time.
So, I would recomend to start with a small step, see how it's gonna be used
and actually get feedback first. Because you can always go stricter if
needed, but removing such a major feature like "strict typehints" probably
gonna be messy as hell, if even possible if it does not work out. Get the
weak type hints in, wrote code, get a feeling for them, understand the
impact and then make an informed decision - do we actually need to go
stricter?
Thanks,
Arvids.
I have similar opinion. Strict typing looks foreign for PHP.
I see, strict type hints may be useful.
Aspecially for testing and error detection, but anyaway, I'm not sure if
and how it should be enabled. Declare() is a working solution, but it's not
excelent.
Thanks. Dmitry.
Hi Dmitry,
I have similar opinion. Strict typing looks foreign for PHP.
It is in a way, yes. PHP has traditionally been “weakly-typed” everywhere.
That being said, we’re not always weakly-typed (there are strict type checks in some places), and userland code has sometimes done strict type checks anyway.
I see, strict type hints may be useful.
Aspecially for testing and error detection, but anyaway, I'm not sure if and how it should be enabled. Declare() is a working solution, but it's not excelent.
It’s not a perfect solution, but I haven’t seen anything that seems to be much better. The best bit about declare() is that it would make strict types completely optional, so people who don’t like them wouldn’t have to use them, even if they call code which does.
--
Andrea Faulds
http://ajf.me/
Hi Dmitry,
I have similar opinion. Strict typing looks foreign for PHP.
It is in a way, yes. PHP has traditionally been “weakly-typed” everywhere.
That being said, we’re not always weakly-typed (there are strict type
checks in some places), and userland code has sometimes done strict type
checks anyway.I see, strict type hints may be useful.
Aspecially for testing and error detection, but anyaway, I'm not sure if
and how it should be enabled. Declare() is a working solution, but it's not
excelent.It’s not a perfect solution, but I haven’t seen anything that seems to be
much better. The best bit about declare() is that it would make strict
types completely optional, so people who don’t like them wouldn’t have to
use them, even if they call code which does.
I agree. It's probably the best solution that we saw. But it's still not
good enough,
It would be great to make the obvious part of the proposal accepted first.
I would suggest to make two separate voting questions.
-
Enable scalar type hinting with standard rules.
-
In addition enable strict type hinting triggered by declare().
Thanks. Dmitry.
--
Andrea Faulds
http://ajf.me/
Hi Dmitry,
could you please write down few use cases, when strict scalar type hints
are really useful.
I'm not opposing to have scalar type hints, but assertion can do better job
for it. I think you have proposed assert()
w/o runtime overhead. Is this
included in PHP7? Enable by opcache, perhaps?
Sorry for OT. I'm curious.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Yasuo,
You probably talk about https://wiki.php.net/rfc/expectations
I wasn't the author of idea, I just helped with thoughts and implantation.
I think it may be useful for PHP7.
Thanks. Dmitry.
Hi Dmitry,
could you please write down few use cases, when strict scalar type hints
are really useful.I'm not opposing to have scalar type hints, but assertion can do better job
for it. I think you have proposedassert()
w/o runtime overhead. Is this
included in PHP7? Enable by opcache, perhaps?Sorry for OT. I'm curious.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Dmitry,
You probably talk about https://wiki.php.net/rfc/expectations
I wasn't the author of idea, I just helped with thoughts and implantation.
I think it may be useful for PHP7.
Thank you for the info.
It would be great to have it for PHP7 indeed.
I'm looking forward to vote.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
De : Dmitry Stogov [mailto:dmitry@zend.com]
Hi Yasuo,You probably talk about https://wiki.php.net/rfc/expectations
I wasn't the author of idea, I just helped with thoughts and implantation.
I think it may be useful for PHP7.
In accordance with Yasuo's suggestions, couldn't we consider assertions as part of a future implementation of the wider 'design by contract' concept ?
DbC could handle :
- function inputs : 'smart' built-in arguments types (keeping loose typing), constraints on possible values
- function output : accepted return types/values
- assertions anywhere in the code
Function input/output validation would be done using built-in 'smart' types ('string', 'numeric', 'integer', etc), and, optionally, 'validator' functions. These could validate any aspect about argument/return type and value. The key point with DbC (as well as assertions) is that, as there's no constraint on performance, validation can be very precise and can run in userland code.
For function input/output validation, I would extend the phpdoc syntax (keeping compatibility with existing comments).
Another suggestion for assertions : if we hide it in comments (something unusual like '//@@assert(...)'), we probably don't need to define an opcode and it can be implemented as a standard function.
The question of whether DbC should replace or just supplement arg/return typing remains open :).
What I suggest, if you agree, is that, even if we don't implement the whole DbC concept now, we could already consider assertions as being part of it, and rename zend.assertions to zend.dbc, assert.exceptions to dbc.exceptions, and AssertException to DbcException.
Regards
François
The idea of that RFC was an ability to have zero-cost assert()
.
DbC is a much more bigger feature, it is interesting, but requires
significant work.
Thanks. Dmitry.
On Wed, Feb 4, 2015 at 10:11 AM, François Laupretre francois@tekwire.net
wrote:
De : Dmitry Stogov [mailto:dmitry@zend.com]
Hi Yasuo,You probably talk about https://wiki.php.net/rfc/expectations
I wasn't the author of idea, I just helped with thoughts and
implantation.
I think it may be useful for PHP7.In accordance with Yasuo's suggestions, couldn't we consider assertions as
part of a future implementation of the wider 'design by contract' concept ?DbC could handle :
- function inputs : 'smart' built-in arguments types (keeping loose
typing), constraints on possible values- function output : accepted return types/values
- assertions anywhere in the code
Function input/output validation would be done using built-in 'smart'
types ('string', 'numeric', 'integer', etc), and, optionally, 'validator'
functions. These could validate any aspect about argument/return type and
value. The key point with DbC (as well as assertions) is that, as there's
no constraint on performance, validation can be very precise and can run in
userland code.For function input/output validation, I would extend the phpdoc syntax
(keeping compatibility with existing comments).Another suggestion for assertions : if we hide it in comments (something
unusual like '//@@assert(...)'), we probably don't need to define an opcode
and it can be implemented as a standard function.The question of whether DbC should replace or just supplement arg/return
typing remains open :).What I suggest, if you agree, is that, even if we don't implement the
whole DbC concept now, we could already consider assertions as being part
of it, and rename zend.assertions to zend.dbc, assert.exceptions to
dbc.exceptions, and AssertException to DbcException.Regards
François
Am 04.02.2015 um 08:25 schrieb Dmitry Stogov:
The idea of that RFC was an ability to have zero-cost
assert()
.
But an assert()
is still in the body of a function or method and
not part of its signature. That is what I want scalar type
declarations for.
hi Sebastian,
Do you like the proposal with declare() switch?
Don't you afraid of sin(1) break? (it's just an example, telling how many
things may be broken).
Thanks. Dmitry.
On Wed, Feb 4, 2015 at 10:30 AM, Sebastian Bergmann sebastian@php.net
wrote:
Am 04.02.2015 um 08:25 schrieb Dmitry Stogov:
The idea of that RFC was an ability to have zero-cost
assert()
.But an
assert()
is still in the body of a function or method and
not part of its signature. That is what I want scalar type
declarations for.
Am 04.02.2015 um 10:25 schrieb Dmitry Stogov:
Do you like the proposal with declare() switch?
No, I do not like that.
We are talking about adding support for scalars (string, integer, ...)
to the list of optional type declarations already supported (array,
callable, interface name, class name) by PHP. When a developer chooses
to use a scalar type in the signature of a function or method then it
should be enforced as strictly as the already supported types. It should
be up the caller to perform explicit type casting when required.
This won't fit into "loosely-typed" PHP, and will lead to writing -
sin((float)$x).
We have this in PHP sources :) (in C)
Thanks. Dmitry.
On Wed, Feb 4, 2015 at 12:31 PM, Sebastian Bergmann sebastian@php.net
wrote:
Am 04.02.2015 um 10:25 schrieb Dmitry Stogov:
Do you like the proposal with declare() switch?
No, I do not like that.
We are talking about adding support for scalars (string, integer, ...)
to the list of optional type declarations already supported (array,
callable, interface name, class name) by PHP. When a developer chooses
to use a scalar type in the signature of a function or method then it
should be enforced as strictly as the already supported types. It should
be up the caller to perform explicit type casting when required.
This won't fit into "loosely-typed" PHP, and will lead to writing -
sin((float)$x).
Hi Dmitry,
I think what people miss is that the place where the conversion from
an unknown type to an int takes place, is also the place where you
would put the human readable reason for why a certain type is needed:
function placeOrder(int $amount){...}
// Throws an exception with the provided message
// if the value cannot be converted to an int.
function getInt($value, $exceptionMessage) : int {...}
function processOrderRequest() {
$amount = getInt($_REQUEST['amount'], "Sorry, the order amount
must be a whole number.");
//Yay, our IDE can tell that $amount is an int if the code reached here.
placeOrder($amount);
}
It's this join point between layers of code that make explicit strict
scalar types be so useful. On one side of that join point we don't
know (and shouldn't care) what the details of the value are. On the
other side of the join point we know that it is an int and don't have
to consider any other types.
I would love to have strict type hints in PHP, and this may sound
contradictory, but they would almost never ever get triggered in my
code. The only time they would be triggered is when there is a mistake
and I have missed converting something to the expected type.
Having the scalar type defined on the parameter allows for code
analysis tools to find errors. This would make cases where I forget to
convert them properly be almost non-existant. With asserts inside the
function those errors would only be detectable at run time.
btw For your exact example sin((float)$x).
this is actually a case
where another scalar type of 'number' which is satisfiable by either a
float or an int would be useful, but that's definitely a step too far
before we have any scalar type hints.
cheers
Dan
btw For your exact example
sin((float)$x).
this is actually a case
where another scalar type of 'number' which is satisfiable by either a
float or an int would be useful, but that's definitely a step too far
before we have any scalar type hints.
We already have a name for that: numeric (is_numeric()).
We all external data convert to native PHP types.
The database we use option MYSQLI_OPT_INT_AND_FLOAT_NATIVE.
HTTP inputs are validated and converted to native PHP types.
In Redis data are stored as serialize string.
Strong typing I like.
Hi!
We are talking about adding support for scalars (string, integer, ...)
to the list of optional type declarations already supported (array,
callable, interface name, class name) by PHP. When a developer chooses
to use a scalar type in the signature of a function or method then it
should be enforced as strictly as the already supported types. It should
be up the caller to perform explicit type casting when required.
That is contrary to the nature of PHP as it has been a weakly typed
language for 20 years. I think it would be a big mistake to change one
of the basic concepts of the language, that has worked pretty well
judging from it adoption. Especially given that all internal functions
do not and will not work this way. Unless you propose make internal
functions work this way too, in which case it'd be much better to change
the name of the project, because there won't be much left that connects
it to prior PHP and you can pretty much forget about BC.
Stas Malyshev
smalyshev@gmail.com
Hi,
Hi!
We are talking about adding support for scalars (string, integer, ...)
to the list of optional type declarations already supported (array,
callable, interface name, class name) by PHP. When a developer chooses
to use a scalar type in the signature of a function or method then it
should be enforced as strictly as the already supported types. It should
be up the caller to perform explicit type casting when required.That is contrary to the nature of PHP as it has been a weakly typed
language for 20 years. I think it would be a big mistake to change one
of the basic concepts of the language, that has worked pretty well
judging from it adoption.
Adding another concept, not changing the existing ones. And really,
it's just simplifying what is already present via is_<typename>()
runtime checks, making our lives a little bit easier.
Though, I should re-iterate - I'm not in favor of picking just one of
the two possibilities.
Especially given that all internal functions
do not and will not work this way. Unless you propose make internal
functions work this way too, in which case it'd be much better to change
the name of the project, because there won't be much left that connects
it to prior PHP and you can pretty much forget about BC.
Cheers,
Andrey.
Hi!
Adding another concept, not changing the existing ones. And really,
it's just simplifying what is already present via is_<typename>()
runtime checks, making our lives a little bit easier.
There's a very big difference between allowing to check types (and then
do whatever you wish) and having functions throw fatal errors if types
do not match.
--
Stas Malyshev
smalyshev@gmail.com
Hi,
Hi!
Adding another concept, not changing the existing ones. And really,
it's just simplifying what is already present via is_<typename>()
runtime checks, making our lives a little bit easier.There's a very big difference between allowing to check types (and then
do whatever you wish) and having functions throw fatal errors if types
do not match.
True, but obviously, us who want strict typehints want to be able to do this:
function foo(int $bar) { /* ... */ }
... instead of something like this:
function foo($bar)
{
if ( ! is_int($bar))
{
trigger_error(sprintf('foo() expects argument 1 ($foo) to
be int, %s given', gettype($bar)), E_USER_ERROR);
exit(1);
}
/* ... */
}
Hence, simplifying. :)
Cheers,
Andrey.
Hi!
True, but obviously, us who want strict typehints want to be able to do this:
Obviously, but it doesn't mean whole language should be changed to serve
one use case, especially the one that goes contrary to what happened in
PHP for decades.
Stas Malyshev
smalyshev@gmail.com
Hi!
True, but obviously, us who want strict typehints want to be able to do this:
Obviously, but it doesn't mean whole language should be changed to serve
one use case, especially the one that goes contrary to what happened in
PHP for decades.
I understand that argument.
However I feel like the fact that it only affects your app (even if
you use a library relying on strictness) if you want to is not clear
for everyone replying here. Is this point clear for you?
--
Pierre
@pierrejoye | http://www.libgd.org
Hi!
However I feel like the fact that it only affects your app (even if
you use a library relying on strictness) if you want to is not clear
for everyone replying here. Is this point clear for you?
I was addressing the idea that every scalar type mention should be
strict. If it is a choice, I am more open to it, even though I think
declare is a very ugly way of doing it. I'd rather have foo(scalar $bar)
for traditional (coercive) scalar typing, and something like foo(scalar!
$bar) (you can bikeshed the syntax if you like) for strict typing. It is
immediately clear what each one does, does not conflict with PHP
tradition, and allows to freely choose and intermix strictness levels as
one's hear desires.
--
Stas Malyshev
smalyshev@gmail.com
Hi!
However I feel like the fact that it only affects your app (even if
you use a library relying on strictness) if you want to is not clear
for everyone replying here. Is this point clear for you?I was addressing the idea that every scalar type mention should be
strict. If it is a choice, I am more open to it, even though I think
declare is a very ugly way of doing it. I'd rather have foo(scalar $bar)
for traditional (coercive) scalar typing, and something like foo(scalar!
$bar) (you can bikeshed the syntax if you like) for strict typing. It is
immediately clear what each one does, does not conflict with PHP
tradition, and allows to freely choose and intermix strictness levels as
one's hear desires.--
Stas Malyshev
smalyshev@gmail.com--
Hi,
the problem with foo(string $bar) and foo(string! $bar) or
foo((string) $bar) is that the writer of the method is deciding, not
the caller - but in both cases, the method gets exactly what it needs
to have, so the way how it should be passed should be upon the caller.
Also, this discussion shows why exactly is it a bad idea to have two
ways of passing parameters - it's a mess and there isn't an ideal way
how to solve it.
Hi,
Hi!
True, but obviously, us who want strict typehints want to be able to do this:
Obviously, but it doesn't mean whole language should be changed to serve
one use case, especially the one that goes contrary to what happened in
PHP for decades.
I never suggested that. The only reason I replied to you is because
you're saying it changes the whole language, and I explicitly said I'm
not in favor of only strict types, just as I'm against having only
weak types.
I just want that one use case to be satisfied, without changing how
the rest of the language works.
Cheers,
Andrey.
Hi!
Adding another concept, not changing the existing ones. And really,
it's just simplifying what is already present via is_<typename>()
runtime checks, making our lives a little bit easier.There's a very big difference between allowing to check types (and then
do whatever you wish) and having functions throw fatal errors if types
do not match.
Totally agree.
However, to be sure everyone understands it, you, as an user of a library
using strict mode, won't see it.
I agree that a library using strict and release untested code may be an
issue, but then it is a bug on the library itself, no biggie to fix.
--
Stas Malyshev
smalyshev@gmail.com
De : Stanislav Malyshev [mailto:smalyshev@gmail.com]
Adding another concept, not changing the existing ones. And really,
it's just simplifying what is already present via is_<typename>()
runtime checks, making our lives a little bit easier.There's a very big difference between allowing to check types (and then
do whatever you wish) and having functions throw fatal errors if types
do not match.
+1. Checking IS_<type> at the C level after implicit conversions and checking this at the PHP level are very different.
IMHO, the key point is the concept of 'type'. Strict typing considers a one-to-one correspondence between PHP types and zval types, which is nonsense. At the PHP level, any value returning true through is_numeric()
IS a 'number', and it must remain so. Any such value with a null decimal part is an 'integer' (not the result of 'is_int()') and so on.
As long as we don't agree on 'smart' high-level types and the corresponding matching rules against zval type and value, we won't agree on anything. This is what I am currently defining in the upcoming DbC RFC. Hopefully, a first version will be released tomorrow, depending on Yasuo's and Dmitry's opinion.
Cheers
François
Hi François,
+1. Checking IS_<type> at the C level after implicit conversions and checking this at the PHP level are very different.
IMHO, the key point is the concept of 'type'. Strict typing considers a one-to-one correspondence between PHP types and zval types, which is nonsense. At the PHP level, any value returning true through
is_numeric()
IS a 'number', and it must remain so. Any such value with a null decimal part is an 'integer' (not the result of 'is_int()') and so on.
This simply isn’t how PHP works. PHP has a limited form of type juggling, but the types of values are not merely an implementation detail. There are numerous places where PHP completely violates the notion that these types don’t matter, such as comparisons, sorting, functions accepting multiple types, functions returning multiple types, bitwise operators and array indexing. All of these discriminate between types. To claim that types are merely an aspect of a zval is ignorance in the extreme.
--
Andrea Faulds
http://ajf.me/
I completely agree.
Strict typing doesn't fit into PHP. It was already told thousand times.
Check the second requirement in RFC template
https://wiki.php.net/rfc/template
Also, the only really useful case for "strict typing" is the ability to
catch mistakes in user apps.
However, this ability is really limited. Implementing "Design by Contact"
approach may be much smarter.
Thanks. Dmitry.
On Thu, Feb 5, 2015 at 3:06 AM, Stanislav Malyshev smalyshev@gmail.com
wrote:
Hi!
We are talking about adding support for scalars (string, integer, ...)
to the list of optional type declarations already supported (array,
callable, interface name, class name) by PHP. When a developer chooses
to use a scalar type in the signature of a function or method then it
should be enforced as strictly as the already supported types. It should
be up the caller to perform explicit type casting when required.That is contrary to the nature of PHP as it has been a weakly typed
language for 20 years. I think it would be a big mistake to change one
of the basic concepts of the language, that has worked pretty well
judging from it adoption. Especially given that all internal functions
do not and will not work this way. Unless you propose make internal
functions work this way too, in which case it'd be much better to change
the name of the project, because there won't be much left that connects
it to prior PHP and you can pretty much forget about BC.Stas Malyshev
smalyshev@gmail.com
Hi,
I completely agree.
Strict typing doesn't fit into PHP. It was already told thousand times.
Seems to work rather well in practice, so long as it’s optional.
Also, the only really useful case for "strict typing" is the ability to catch mistakes in user apps.
However, this ability is really limited. Implementing "Design by Contact" approach may be much smarter.
It’s not that limited. I caught two different bugs in my app simply by adding strict types.
Strict typing, crucially, allows the catching of errors ahead of time, too. You can’t do that with weak typing, because it depends on the value, not the type. And you don’t know the value from reading the source code.
--
Andrea Faulds
http://ajf.me/
Hi,
I completely agree.
Strict typing doesn't fit into PHP. It was already told thousand times.Seems to work rather well in practice, so long as it’s optional.
"works" and "fits" are different.
Also, the only really useful case for "strict typing" is the ability to
catch mistakes in user apps.
However, this ability is really limited. Implementing "Design by
Contact" approach may be much smarter.It’s not that limited. I caught two different bugs in my app simply by
adding strict types.Strict typing, crucially, allows the catching of errors ahead of time,
too. You can’t do that with weak typing, because it depends on the value,
not the type. And you don’t know the value from reading the source code.
Strict type hinting may help catching problems only at run-time.
In PHP you almost never can do something ahead of time, because of run-time
binding.
You may only guess, analyzing the whole projects and performing type
inference.
Thanks. Dmitry.
--
Andrea Faulds
http://ajf.me/
Hi,
"works" and "fits" are different.
Fair point.
Strict type hinting may help catching problems only at run-time.
In PHP you almost never can do something ahead of time, because of run-time binding.
You may only guess, analyzing the whole projects and performing type inference.
This is true to an extent. However, there are still some things you can catch ahead-of-time. One of the things strict mode caught could’ve been noticed by a static analyser. The other probably wouldn’t have been. Strict typing tends to be better for catching errors ahead-of-time, and I think with return types it’ll get even better.
Thanks for your input.
--
Andrea Faulds
http://ajf.me/
-----Ursprüngliche Nachricht-----
Von: Dmitry Stogov [mailto:dmitry@zend.com]
Gesendet: Mittwoch, 4. Februar 2015 10:26
An: Sebastian Bergmann
Cc: PHP Internals
Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for?hi Sebastian,
Do you like the proposal with declare() switch?
Don't you afraid of sin(1) break? (it's just an example, telling how many things may be broken).Thanks. Dmitry.
On Wed, Feb 4, 2015 at 10:30 AM, Sebastian Bergmann sebastian@php.net
wrote:Am 04.02.2015 um 08:25 schrieb Dmitry Stogov:
The idea of that RFC was an ability to have zero-cost
assert()
.But an
assert()
is still in the body of a function or method and not
part of its signature. That is what I want scalar type declarations
for.--
To unsubscribe,
visit: http://www.php.net/unsub.php
Personally I am not in favour of the declare approach because the user will need to switch between strict context and non-strict context which will be quite challenging, anti-efficient (in terms of productivity) and most probably another source for bugs.
Yet, I have to defend Andrea's RFC here since the claims made that it will break all kind of existing code is just not true (or I got the RFC completely wrong).
sin(1) would only be broken if and only if the user has decided to use it in a strict mode. Consider the following:
User A writes the file index.php
<?php
$a = sin(1); //perfectly fine
include 'test_strict.php'
?>
and user B writes test_strict.php
<?php
declare(strict=1);
$b = sin(1); //will fail and that's ok [*] since the user decided to be in strict mode
?>
As far as I can tell user A which want to code in non-strict mode could do so also in the future - no error is reported, no problem at all. Only user B would get the error and only because he/she wanted to be informed when his/her code is not strict.
[*] we could actually distinguish between int literals/constants and int variables. The above case would be fine as well since 1 can be int or float (pretty much as Haskell is handling it)
Hi Robert,
Personally I am not in favour of the declare approach because the user will need to switch between strict context and non-strict context which will be quite challenging, anti-efficient (in terms of productivity) and most probably another source for bugs.
I’ve found this not to be quite true in practice. When I ported my app to use strict scalar hints, very little broke - and this is an app that took advantage of weak typing everywhere. I realise switching contexts might be a little painful, but it doesn’t seem to be as bad as I expected. It looks to me like much PHP code is already fairly strict and consistent with its types.
I think it’s mostly just edge cases where things break with strict types on. Any strict code will work fine as “weak” code, and most weak code will work fine as strict code, I think.
Yet, I have to defend Andrea's RFC here since the claims made that it will break all kind of existing code is just not true (or I got the RFC completely wrong).
sin(1) would only be broken if and only if the user has decided to use it in a strict mode. Consider the following:
User A writes the file index.php
<?php
$a = sin(1); //perfectly fine
include 'test_strict.php'
?>and user B writes test_strict.php
<?php
declare(strict=1);
$b = sin(1); //will fail and that's ok [*] since the user decided to be in strict mode
?>As far as I can tell user A which want to code in non-strict mode could do so also in the future - no error is reported, no problem at all. Only user B would get the error and only because he/she wanted to be informed when his/her code is not strict.
[*] we could actually distinguish between int literals/constants and int variables. The above case would be fine as well since 1 can be int or float (pretty much as Haskell is handling it)
Yeah, I only had int/float issues when I turned on strict mode in my app. And that caught a bug, actually, so I was quite thankful for it.
--
Andrea Faulds
http://ajf.me/
Hi Dmitry,
The idea of that RFC was an ability to have zero-cost
assert()
.DbC is a much more bigger feature, it is interesting, but requires
significant work.
Type check and DbC integration would require significant work, I guess.
If you say so, it is.
How about simple in{}, out{} block? I expect it's much simpler.
Injecting in{} and out{} block code to before/after execute() something
like this.
If execute() is replaceable as before, then we may have two execute()
for production and development. There will be zero performance cost
hopefully.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
I mean a lot of work designing this concept properly, writing RFC,
discussing, coming to consensus, etc
The implementation itself may be quite simple.
If anyone can take care about design, I may help with implementation.
Thanks. Dmitry.
Hi Dmitry,
The idea of that RFC was an ability to have zero-cost
assert()
.DbC is a much more bigger feature, it is interesting, but requires
significant work.Type check and DbC integration would require significant work, I guess.
If you say so, it is.How about simple in{}, out{} block? I expect it's much simpler.
Injecting in{} and out{} block code to before/after execute() something
like this.
If execute() is replaceable as before, then we may have two execute()
for production and development. There will be zero performance cost
hopefully.Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Dmitry,
I mean a lot of work designing this concept properly, writing RFC,
discussing, coming to consensus, etc
The implementation itself may be quite simple.
If anyone can take care about design, I may help with implementation.
Great to hear this!
I would like to help, but I've only written some zend extensions and don't
know
about Zend internal much. I may handle RFC/discussion/consensus, but
I probably don't have enough time to learn Zend internal. If you are okay
with
this, I'll write/discuss RFC and get consensus hopefully.
If any Zend experts would like to help design or take care of this all, I
appreciate it a lot!
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
If you write draft RFC, and I like it, I'll take care about implementation.
Most probably implementation may cause some changes in design.
For now, I may just guess, how it should look like from user perspective.
Thanks. Dmitry.
Hi Dmitry,
I mean a lot of work designing this concept properly, writing RFC,
discussing, coming to consensus, etc
The implementation itself may be quite simple.
If anyone can take care about design, I may help with implementation.Great to hear this!
I would like to help, but I've only written some zend extensions and don't
know
about Zend internal much. I may handle RFC/discussion/consensus, but
I probably don't have enough time to learn Zend internal. If you are okay
with
this, I'll write/discuss RFC and get consensus hopefully.If any Zend experts would like to help design or take care of this all, I
appreciate it a lot!Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Dmitry,
If you write draft RFC, and I like it, I'll take care about implementation.
Most probably implementation may cause some changes in design.For now, I may just guess, how it should look like from user perspective.
Francois volunteered to write phpdoc enabled proposal.
I'll write D language like proposal. We'll send mail when draft RFC is
ready.
Thank you!
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
De : Dmitry Stogov [mailto:dmitry@zend.com]
The idea of that RFC was an ability to have zero-cost
assert()
.DbC is a much more bigger feature, it is interesting, but requires significant work.
I agree. My suggestion was just to consider assertions as part of this future work (by using 'dbc' instead of 'assert' in naming, which will be cleaner when we implement the whole concept in the future).
François
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // casting
This was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.
Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.
Hi Leigh,
Le 4 févr. 2015 11:50, "Leigh" leight@gmail.com a écrit :
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // castingThis was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.
Because it is then the callee who decides, not the caller, whether or not
he wants strict typing.
--
Cheers,
Florian Margaine
Hi,
Hi Leigh,
Le 4 févr. 2015 11:50, "Leigh" leight@gmail.com a écrit :
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // castingThis was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.Because it is then the callee who decides, not the caller, whether or not
he wants strict typing.
... and apparently, this is the root of all evil. :)
I am baffled by how the two-syntaxes suggestion is always so easily
dismissed by that argument. I'd argue that most people who support the
current proposal don't fully understand what declare(strict_type=1)
really does. As I've previously said - putting the caller in control
(and really the caller, not in a per-file context) makes it a
debugging tool, not support for strict typing.
Cheers,
Andrey.
Hi,
On Wed, Feb 4, 2015 at 1:02 PM, Florian Margaine florian@margaine.com
wrote:Hi Leigh,
Le 4 févr. 2015 11:50, "Leigh" leight@gmail.com a écrit :
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // castingThis was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.Because it is then the callee who decides, not the caller, whether or
not
he wants strict typing.... and apparently, this is the root of all evil. :)
I am baffled by how the two-syntaxes suggestion is always so easily
dismissed by that argument. I'd argue that most people who support the
current proposal don't fully understand what declare(strict_type=1)
really does. As I've previously said - putting the caller in control
(and really the caller, not in a per-file context) makes it a
debugging tool, not support for strict typing.
On the same line I think almost nobody here tries it. Code can make things
easier to understand. On the other hand this debate has reached a sterile
state.
Try it, play with some small scripts, existing codes, report eventual
issues (maybe related to this rfc or bugs in 7). That will help much more
than what is being discussed endlessly here.
Hi again,
Hi Leigh,
Le 4 févr. 2015 11:50, "Leigh" leight@gmail.com a écrit :
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // castingThis was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.Because it is then the callee who decides, not the caller, whether or not
he wants strict typing.... and apparently, this is the root of all evil. :)
It’s not “the root of all evil". But the two-syntax approach has disadvantages I’ve elaborated numerous times.
It shifts the choice to the callee, not the caller. This means existing applications are broken if strict hints are added to existing libraries. It means that programmers will have to deal with two different systems, simultaneously, in the same file or function or method, because one API uses (int) and the other uses int. It means that if the API author decides to have weak types, you are prevented by the language from having the benefits of strict typing, even if you want them. It also has a syntax issue: (int) looks like an explicit cast, yet what is usually proposed doesn’t something similar. There’s also the consistency issue in that we’d have to support real for consistency with (real), since T_DOUBLE_CAST
is a token. It means that internal functions could now also use strict hints - or if they can’t, we have a consistency issue. It means beginners, and people who don’t like strict types, now have to deal with strict types in their code, despite PHP always having been a weakly-typed, beginner-friendly language. And so on, and so forth.
The current RFC deliberately does not propose this because I think it causes more problems then it solves.
I am baffled by how the two-syntaxes suggestion is always so easily
dismissed by that argument. I'd argue that most people who support the
current proposal don't fully understand what declare(strict_type=1)
really does.
Well, I understand what it does. I’ve used it. It worked really, fantastically well… better than I expected it to. It provided benefits that the two-syntax suggestion wouldn’t have. It provided benefits that just strict hints wouldn’t have. It provided benefits that just weak hints wouldn’t have.
As I've previously said - putting the caller in control
(and really the caller, not in a per-file context) makes it a
debugging tool, not support for strict typing.
What’s the difference between “per-file” and “really the caller”? The RFC does allow you to use declare() blocks if you really want to.
Also, type hints are mostly a debugging tool anyway. They’re a tool for catching errors early, and to enable better documentation. That’s all that they do.
--
Andrea Faulds
http://ajf.me/
Hi Andrea,
Hi again,
Hi Leigh,
Le 4 févr. 2015 11:50, "Leigh" leight@gmail.com a écrit :
What was wrong with:
function x(int $y, string $z) { // strict
function x((int) $y, (string) $z) { // castingThis was the best suggestion I've seen that covers the requirements of
both camps, and is still very clear how data is going to be handled.Authors who want their APIs to adhered to strictly can do that,
authors who want to accept anything and have it end up as their
desired type can do that too.Because it is then the callee who decides, not the caller, whether or not
he wants strict typing.... and apparently, this is the root of all evil. :)
It’s not “the root of all evil". But the two-syntax approach has disadvantages I’ve elaborated numerous times.
It shifts the choice to the callee, not the caller. This means existing applications are broken if strict hints are added to existing libraries. It means that programmers will have to deal with two different systems, simultaneously, in the same file or function or method, because one API uses (int) and the other uses int. It means that if the API author decides to have weak types, you are prevented by the language from having the benefits of strict typing, even if you want them. It also has a syntax issue: (int) looks like an explicit cast, yet what is usually proposed doesn’t something similar. There’s also the consistency issue in that we’d have to support real for consistency with (real), since
T_DOUBLE_CAST
is a token. It means that internal functions could now also use strict hints - or if they can’t, we have a consistency issue. It means beginners, and people who don’t like strict types, now have to deal with strict types in their code, despite PHP always having been a weakly-typed, beginner-friendly language. And so on, and so forth.The current RFC deliberately does not propose this because I think it causes more problems then it solves.
I am baffled by how the two-syntaxes suggestion is always so easily
dismissed by that argument. I'd argue that most people who support the
current proposal don't fully understand what declare(strict_type=1)
really does.Well, I understand what it does.
That's an own goal (in football/soccer terms), you know. ;)
I’ve used it. It worked really, fantastically well… better than I expected it to. It provided benefits that the two-syntax suggestion wouldn’t have. It provided benefits that just strict hints wouldn’t have. It provided benefits that just weak hints wouldn’t have.
As I've previously said - putting the caller in control
(and really the caller, not in a per-file context) makes it a
debugging tool, not support for strict typing.What’s the difference between “per-file” and “really the caller”? The RFC does allow you to use declare() blocks if you really want to.
Also, type hints are mostly a debugging tool anyway. They’re a tool for catching errors early, and to enable better documentation. That’s all that they do.
Yeah, you've said that numerous times ... almost as much as I have
disagreed with your arguments.
I didn't want to turn this thread into a re-iteration of the RFC
discussion one. I'm just completely surprised how relentlessly all
suggestions about two syntaxes have been waved off by a callee vs
caller argument like it's a golden rule or something ... it's not, you
just don't like the other approach.
Cheers,
Andrey.
Hi,
I didn't want to turn this thread into a re-iteration of the RFC
discussion one. I'm just completely surprised how relentlessly all
suggestions about two syntaxes have been waved off by a callee vs
caller argument like it's a golden rule or something ... it's not, you
just don't like the other approach.
I think it’s a shorthand for listing, again, all the problems with shifting the choice onto the caller.
The subject has been debated to death. People aren’t being dismissive - the problems with it have already been covered extensively.
Andrea Faulds
http://ajf.me/
Because it is then the callee who decides, not the caller, whether or not he
wants strict typing.
And that is the way it should be.