With all the new typing and strict mode in PHP7, I'm wondering if there is
any planned support for typing of properties in a future version. IE
something like:
class Foo {}
class Bar {
public Foo $foo;
public function __construct(Foo $foo) {
$this->foo = $foo;
}
}
This seems really useful to me. If its not something that was considered
before I can try to write up an RFC for this, however I'm not sure if this
was already considered and denied. Any feedback would be greatly
appreciated.
-Ryan
+1
It will be useful for autocomplete in IDE
Am 11.07.2015 um 19:53 schrieb S.A.N:
It will be useful for autocomplete in IDE
That argument is bogus since proper IDEs (PhpStorm, fex.) leverage
docblock annotations for that already.
On Sat, Jul 11, 2015 at 12:41 PM, Sebastian Bergmann sebastian@php.net
wrote:
Am 11.07.2015 um 19:53 schrieb S.A.N:
It will be useful for autocomplete in IDE
That argument is bogus since proper IDEs (PhpStorm, fex.) leverage
docblock annotations for that already.Agreed. I don't know any IDE meant for PHP that doesn't respect docblock
declarations.
I think the benefit comes more in being able to make a property public, and
still have control over its type. Currently the only way to do it is to
have your property be private and use public get/set method(s) instead. IE:
class foo {
public int $bar;
}
-- vs. --
class foo {
private $bar = 0;
public function getBar() : int {
return $this->bar;
}
public function setBar(int $val) {
$this->bar = $val;
}
}
Granted its still far less verbose for scalar types than in the current 5.x
world where you have to have your own type checks as well.
Hi,
2015-07-11 15:41 GMT-03:00 Sebastian Bergmann sebastian@php.net:
Am 11.07.2015 um 19:53 schrieb S.A.N:
It will be useful for autocomplete in IDE
That argument is bogus since proper IDEs (PhpStorm, fex.) leverage
docblock annotations for that already.--
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.
Marcio
Hi!
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.
I don't see "not needing to write docblocks" as a win, quite the
contrary. In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.
While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.
--
Stas Malyshev
smalyshev@gmail.com
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.
I don't see "not needing to write docblocks" as a win, quite the
contrary. In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.
In addition, the docblock contains a lot more material than just a few
types, so one still needs to have one. The main problem with adding
types is they become part of the code, while a docblock can simple be
stripped.
As a 'minor win for IDE users' it is also questionable since the every
IDE will need to be re-written to support both methods of working.
--
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
Lester,
2015-07-12 5:27 GMT-03:00 Lester Caine lester@lsces.co.uk:
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.
I don't see "not needing to write docblocks" as a win, quite the
contrary. In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.In addition, the docblock contains a lot more material than just a few
types, so one still needs to have one. The main problem with adding
types is they become part of the code, while a docblock can simple be
stripped.
Please refer to reply given to Stas.
As a 'minor win for IDE users' it is also questionable since the every
IDE will need to be re-written to support both methods of working.
You meant "updated" not "re-written". IDEs that want to stay relevant
to the community will always be updated, and hæck, it's much easier to
analyze real language syntax as opposed to uncertain user space DSLs
inside comments. IDE maintainers won't complain about that, for sure.
Marcio
Of course the main target - check types, but not all use the check
types, but almost everyone uses Ide, so I said, it is actual and
useful.
I do not see contradictions, everyone who wants to write PHP 5 code,
need use DocBlock @var.
I hope that in the PHP 7.x, DocBlock is only for documentation of
code, all declared types be in the language and not in the comments
I would like it to be implemented, not beginning of unnecessary disputes.
Thank.
Stas,
2015-07-12 5:10 GMT-03:00 Stanislav Malyshev smalyshev@gmail.com:
Hi!
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.I don't see "not needing to write docblocks" as a win, quite the
contrary.
Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) just
to have a "@var" so your IDE can work?
Not to mention you won't get any runtime/compile time check or
optimization from docblock tags, that's the main point of having typed
properties.
In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.
If you are using the term "proper documentation" to justify docblocks
everywhere even if they contain just a "/** @var string */", it's a
sign we've been using comments against us all this time (even if we
called it "doc comments").
But thankfully we are moving PHP to another direction. Do you remember
the "return types" voting results?
https://wiki.php.net/rfc/return_types#vote. That's because "function()
: type" is self documented and much more maintainable than than a
possibly sloppy "/** @return type */" on top of every method on a
codebase.
While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.
But with the benefits already cited above. Docblocks should not be a
place for type information anymore, this was a workaround and we've
been slowly replacing it with a better solution (opt in types).
Property types seems to be the next logical step after adding return
types and scalar types.
--
Stas Malyshev
smalyshev@gmail.com
Is there any technical reason for you to be against typed properties?
IMMO, just arguing against opt in type declarations (evolving the php
type system) in favor of docblocks (stagnation) seems to be utterly
unproductive as we already know the tendencies from previous votings.
Marcio
Stas,
2015-07-12 5:10 GMT-03:00 Stanislav Malyshev smalyshev@gmail.com:
Hi!
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.
I don't see "not needing to write docblocks" as a win, quite the
contrary.
Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) just
to have a "@var" so your IDE can work?Not to mention you won't get any runtime/compile time check or
optimization from docblock tags, that's the main point of having typed
properties.In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.If you are using the term "proper documentation" to justify docblocks
everywhere even if they contain just a "/** @var string */", it's a
sign we've been using comments against us all this time (even if we
called it "doc comments").But thankfully we are moving PHP to another direction. Do you remember
the "return types" voting results?
https://wiki.php.net/rfc/return_types#vote. That's because "function()
: type" is self documented and much more maintainable than than a
possibly sloppy "/** @return type */" on top of every method on a
codebase.While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.But with the benefits already cited above. Docblocks should not be a
place for type information anymore, this was a workaround and we've
been slowly replacing it with a better solution (opt in types).
Property types seems to be the next logical step after adding return
types and scalar types.
I don't know why we're even talking about IDEs here. IDE
auto-completion isn't the point, anymore than it was the point for
scalar type hints or return type hints. It's about the language doing
type checking for you and static analysis, so that the language can find
bugs for you. Eg:
class Foo {
public Bar $bar;
}
$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler can
check it for you.
That's what the benefit would be. Easier IDE auto-completion is a nice
extra, but not the main goal.
+1 from me in 7.1.
--Larry Garfield
What about arrays? How do I declare Foo[] ?
http://ocramius.github.io/extremely-defensive-php/#/69
2015-07-12 16:37 GMT-03:00 Larry Garfield larry@garfieldtech.com:
Stas,
2015-07-12 5:10 GMT-03:00 Stanislav Malyshev smalyshev@gmail.com:
Hi!
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.I don't see "not needing to write docblocks" as a win, quite the
contrary.Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) just
to have a "@var" so your IDE can work?Not to mention you won't get any runtime/compile time check or
optimization from docblock tags, that's the main point of having typed
properties.In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.If you are using the term "proper documentation" to justify docblocks
everywhere even if they contain just a "/** @var string */", it's a
sign we've been using comments against us all this time (even if we
called it "doc comments").But thankfully we are moving PHP to another direction. Do you remember
the "return types" voting results?
https://wiki.php.net/rfc/return_types#vote. That's because "function()
: type" is self documented and much more maintainable than than a
possibly sloppy "/** @return type */" on top of every method on a
codebase.While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.But with the benefits already cited above. Docblocks should not be a
place for type information anymore, this was a workaround and we've
been slowly replacing it with a better solution (opt in types).
Property types seems to be the next logical step after adding return
types and scalar types.I don't know why we're even talking about IDEs here. IDE auto-completion
isn't the point, anymore than it was the point for scalar type hints or
return type hints. It's about the language doing type checking for you and
static analysis, so that the language can find bugs for you. Eg:class Foo {
public Bar $bar;
}$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler can
check it for you.That's what the benefit would be. Easier IDE auto-completion is a nice
extra, but not the main goal.+1 from me in 7.1.
--Larry Garfield
What about arrays? How do I declare Foo[] ?
http://ocramius.github.io/extremely-defensive-php/#/69
2015-07-12 16:37 GMT-03:00 Larry Garfield larry@garfieldtech.com:
Stas,
2015-07-12 5:10 GMT-03:00 Stanislav Malyshev smalyshev@gmail.com:
Hi!
Not completely bogus. At least with typed properties you won't need to
actually write the docblocks to have the IDE "hints". It's a minor win
for IDE users too.I don't see "not needing to write docblocks" as a win, quite the
contrary.Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) just
to have a "@var" so your IDE can work?Not to mention you won't get any runtime/compile time check or
optimization from docblock tags, that's the main point of having typed
properties.In fact, in a number of projects I worked with, code without
proper documentation (including docblocks) simply wasn't accepted into
the repository.If you are using the term "proper documentation" to justify docblocks
everywhere even if they contain just a "/** @var string */", it's a
sign we've been using comments against us all this time (even if we
called it "doc comments").But thankfully we are moving PHP to another direction. Do you remember
the "return types" voting results?
https://wiki.php.net/rfc/return_types#vote. That's because "function()
: type" is self documented and much more maintainable than than a
possibly sloppy "/** @return type */" on top of every method on a
codebase.While I don't think this needs to be mandatory, I also don't see major
difference - so you have to write type instead of docblock, you still
have to write something.But with the benefits already cited above. Docblocks should not be a
place for type information anymore, this was a workaround and we've
been slowly replacing it with a better solution (opt in types).
Property types seems to be the next logical step after adding return
types and scalar types.I don't know why we're even talking about IDEs here. IDE auto-completion
isn't the point, anymore than it was the point for scalar type hints or
return type hints. It's about the language doing type checking for you
and
static analysis, so that the language can find bugs for you. Eg:class Foo {
public Bar $bar;
}$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler can
check it for you.That's what the benefit would be. Easier IDE auto-completion is a nice
extra, but not the main goal.+1 from me in 7.1.
--Larry Garfield
Since there is not typed arrays in PHP I would say you declare it as an
array. Though in this case I would suggest a collection class that
implements iterator and countable and type hint for this collection and
make its job be to be a container of a specific type.
class WagonCollection implements Iterator, Countable {
private array $wagons = [];
private int $index = 0;
public function addWagon(Wagon $w) {
$this->wagons[] = $w;
}
// implementations for Iterator and Countable
}
However, I could see an argument being made for typed arrays, but that is
not the point of my suggested RFC and a separate RFC would need to be
created for that.
PS. Please bottom post instead of top posting. mailing list rules
<http://git.php.net/?p=php-src.git;a=blob_plain;f=README.MAILINGLIST_RULES;hb=HEAD
I don't know why we're even talking about IDEs here. IDE
auto-completion isn't the point, anymore than it was the point for
scalar type hints or return type hints. It's about the language doing
type checking for you and static analysis, so that the language can find
bugs for you. Eg:class Foo {
public Bar $bar;
}$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler can
check it for you.That's what the benefit would be. Easier IDE auto-completion is a nice
extra, but not the main goal.+1 from me in 7.1.
I am not sure static analysis is a great argument for it either. A
static analyzer can read the docblock really easily too since it is part
of the AST node for the property. In fact I just wrote one. Feeding it
your code example:
% cat -n test.php
1 <?php
2 class Baz { }
3 class Foo {
4 /** @var Bar $bar */
5 public $bar;
6 }
7
8 $f = new Foo();
9 $f->bar = new Baz();
% ./phan test.php
Files scanned: 1
Time: 0.11s
Classes: 2
Methods: 0
Functions: 0
Closures: 0
Traits: 0
Conditionals: 0
Issues found: 1
test.php:9 TypeError property is declared to be bar but was assigned Baz
Plus, without union types, doc-comment typing is much more convenient
when it comes to running a static analyzer on real-world code since
limiting everything to a single type is often impractical. If you grep
through existing code in the wirld, you will find a ton of Bar|bool,
Bar|Baz|bool|null, etc.
I'm not against the idea, but it is quite different from the existing
type checking since this is a type check that would need to be done on
every assignment for it to make any sense at all and not just at call
boundaries like the existing ones. It may not be feasible to do in an
efficient manner. A static analyzer can get away with catching 95%. A
core language feature can't. Having to do these the type check on
assignment will likely require some significant changes to the engine.
-Rasmus
I don't know why we're even talking about IDEs here. IDE
auto-completion isn't the point, anymore than it was the point for
scalar type hints or return type hints. It's about the language doing
type checking for you and static analysis, so that the language can find
bugs for you. Eg:class Foo {
public Bar $bar;
}$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler can check it for you
By the way, I forgot to add that you can't possibly say that this line
is clearly wrong without knowing what Baz is and you didn't define Baz.
So the only thing clearly wrong with that line is that the Baz class
doesn't exist which has nothing to do with the property type.
If you have:
class Bar { }
class Baz extends Bar { }
Then that line is perfectly valid since Baz is an instance of Bar which
would meet the type criteria provided. And this also shows that the
compiler can't actually check that necessarily. We don't know whether
Baz is an instance of Bar at compile-time.
-Rasmus
-----Ursprüngliche Nachricht-----
Von: Rasmus Lerdorf [mailto:rasmus@lerdorf.com]
Gesendet: Montag, 13. Juli 2015 02:12
An: Larry Garfield; internals@lists.php.net
Betreff: Re: [PHP-DEV] PHP7 and typesI don't know why we're even talking about IDEs here. IDE
auto-completion isn't the point, anymore than it was the point for
scalar type hints or return type hints. It's about the language doing
type checking for you and static analysis, so that the language can
find bugs for you. Eg:class Foo {
public Bar $bar;
}$f = new Foo();
$f->bar = new Baz(); // This line is clearly wrong and the compiler
can check it for you.That's what the benefit would be. Easier IDE auto-completion is a
nice extra, but not the main goal.+1 from me in 7.1.
I am not sure static analysis is a great argument for it either. A static analyzer can read the docblock really easily too since it
is part of the AST node for the property. In fact I just wrote one. Feeding it your code example:% cat -n test.php
1 <?php
2 class Baz { }
3 class Foo {
4 /** @var Bar $bar */
5 public $bar;
6 }
7
8 $f = new Foo();
9 $f->bar = new Baz();% ./phan test.php
Files scanned: 1
Time: 0.11s
Classes: 2
Methods: 0
Functions: 0
Closures: 0
Traits: 0
Conditionals: 0
Issues found: 1test.php:9 TypeError property is declared to be bar but was assigned Baz
Plus, without union types, doc-comment typing is much more convenient when it comes to running a static analyzer on
real-world code since limiting everything to a single type is often impractical. If you grep through existing code in the wirld,
you will find a ton of Bar|bool,
Bar|Baz|bool|null, etc.I'm not against the idea, but it is quite different from the existing type checking since this is a type check that would need to
be done on every assignment for it to make any sense at all and not just at call boundaries like the existing ones. It may not
be feasible to do in an efficient manner. A static analyzer can get away with catching 95%. A core language feature can't.
Having to do these the type check on assignment will likely require some significant changes to the engine.-Rasmus
Another point of discussion should be how strict a property type hint will be. Currently, parameter type hints are only binding for the call side but not within the function body.
For instance, function foo(Foo $x){ $x = 1;} is perfectly valid. It certainly has little sense to have the same semantics for properties but then we introduce another inconsistency and should maybe fix the behaviour of parameter type hints first.
Another point of discussion should be how strict a property type hint will be. Currently, parameter type hints are only binding for the call side but not within the function body.
For instance, function foo(Foo $x){ $x = 1;} is perfectly valid. It certainly has little sense to have the same semantics for properties but then we introduce another inconsistency and should maybe fix the behaviour of parameter type hints first.
Like I said, adding type checks to every assignment is a rather large
change, and I doubt it can be done without some nasty performance costs.
Honestly, I would rather have a speedy runtime and put the effort into a
static analysis mode built into PHP. The stated goal of so many who push
the strict types everywhere argument is that it helps find bugs. So
let's have an analyze mode that finds these bugs without bogging down
the runtime with thousands of type checks.
-Rasmus
Like I said, adding type checks to every assignment is a rather large
change, and I doubt it can be done without some nasty performance costs.Honestly, I would rather have a speedy runtime and put the effort into a
static analysis mode built into PHP. The stated goal of so many who push
the strict types everywhere argument is that it helps find bugs. So
let's have an analyze mode that finds these bugs without bogging down
the runtime with thousands of type checks.-Rasmus
Given the size of the change is possibly much larger than I expected. And
given that I'm new to the core and its probably not within my wheelhouse to
create such a large change, I'm probably not the right person to do the
work. As such I think this thread will just die, unless someone wants to
volunteer for the work - in which case I would be glad to offer an help I
can and write up and manage the RFC.
Thanks for all your thoughtful responses!
Hi!
Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) just
Yes. What is obvious to you today may not be at all obvious to your
coworker two years later.
to have a "@var" so your IDE can work?
No, not "just" my IDE can work. IDE is just the side effect. Proper
documentation does much more than that.
Not to mention you won't get any runtime/compile time check or
optimization from docblock tags, that's the main point of having typed
properties.
I don't see how "compile time check" is even possible, given that PHP
has no "compile time". As for runtime check, it'd be mostly useless for
me - I very rarely have seen bugs that would be caught by such checks.
If you are using the term "proper documentation" to justify docblocks
everywhere even if they contain just a "/** @var string */", it's a
sign we've been using comments against us all this time (even if we
called it "doc comments").
I'm not sure what "using comments against us" even means. I also do not
share a superstition that comments are somehow evil or that making
comments machine-readable and benefiting from it is somehow wrong.
But thankfully we are moving PHP to another direction. Do you remember
If you refer to inserting static typing into random places in service of
a cargo cult notion that "more type definitions is always better,
because types fix bugs" - no, I do not think it is a correct direction.
https://wiki.php.net/rfc/return_types#vote. That's because "function()
: type" is self documented and much more maintainable than than a
possibly sloppy "/** @return type */" on top of every method on a
codebase.
It's not more maintainable and it is much less flexible or useful. PHP
has very nice and flexible capabilities that allow write very nice code
which can return different values in different circumstances. By trying
to shove it into a single type you are ignoring these capabilities -
again because of a superstition that somehow there are myriads of bugs
caused by accidentally returning values of wrong types that are being
fixed by that.
But with the benefits already cited above. Docblocks should not be a
place for type information anymore, this was a workaround and we've
Why? There's no reason why they can't be except for a unsupported
statement "it is bad because it is bad".
Stas Malyshev
smalyshev@gmail.com
Hi!
Of course it's a win. Or do you like to write docblocks for every
single class property or method (even when the member is obvious) justYes. What is obvious to you today may not be at all obvious to your
coworker two years later.to have a "@var" so your IDE can work?
No, not "just" my IDE can work. IDE is just the side effect. Proper
documentation does much more than that.
It seems to go off topic. Docblocks are only slightly related to this
thread. The same could be said about annotation (which are widely used too).
I do like the idea to be allowed to do such thing. It is indeed not a high
priority but still nice to have.
Cheers,
Pierre
No, not "just" my IDE can work. IDE is just the side effect. Proper
documentation does much more than that.
It seems to go off topic. Docblocks are only slightly related to this
thread. The same could be said about annotation (which are widely used too).
Coming from a background of 'traditional' php design, all of my code and
the libraries I use are documented via phpdoc style annotation which the
IDE picks up, and phpdocumentor1 produced a good API description. This
was also a GOOD basis to tidy up the various changes through PHP5.x
Today much of the infrastructure to make that work is broken and
http://lsces.org.uk/wiki/bitweaver+documentation is a starting point at
getting the material all up to date. The original documentation had a
few errors on the log file, but http://lsces.org.uk/bwdocs2/index.html
is the version I've been working on and is listing 3300 errors in the
documentation! The next step is to work out how to address those errors,
but once again that is unproductive work so perhaps fixing the problems
with the older V1 documenter may be a better use of time? The rules
phpdocumenter2 follow seem far adrift from the original 'standard'. So
it WOULD be nice if there was an approved standard rather than these
seeming to be subject to different interpretation all the time.
This before addressing the problems of PHP7 migration ...
--
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
Hi Lester,
No, not "just" my IDE can work. IDE is just the side effect. Proper
documentation does much more than that.
It seems to go off topic. Docblocks are only slightly related to this
thread. The same could be said about annotation (which are widely used
too).Coming from a background of 'traditional' php design, all of my code and
the libraries I use are documented via phpdoc style annotation which the
IDE picks up, and phpdocumentor1 produced a good API description. This
was also a GOOD basis to tidy up the various changes through PHP5.xToday much of the infrastructure to make that work is broken and
http://lsces.org.uk/wiki/bitweaver+documentation is a starting point at
getting the material all up to date. The original documentation had a
few errors on the log file, but http://lsces.org.uk/bwdocs2/index.html
is the version I've been working on and is listing 3300 errors in the
documentation! The next step is to work out how to address those errors,
but once again that is unproductive work so perhaps fixing the problems
with the older V1 documenter may be a better use of time? The rules
phpdocumenter2 follow seem far adrift from the original 'standard'. So
it WOULD be nice if there was an approved standard rather than these
seeming to be subject to different interpretation all the time.This before addressing the problems of PHP7 migration ...
Please refer to https://github.com/php-fig/fig-standards/pull/169
Greets,
Marco Pivetta
Please refer to https://github.com/php-fig/fig-standards/pull/169
This just adds another level of complication. FIG is not part of the
core PHP standards, and some of their choices simply don't fit with
legacy code. I suspect that some of the problems I'm currently hitting
are because the coding standards I follow do not match FIG ... and I
have no intentions of adding that to that todo list ... but I've paid
work to get on with currently before I can get back to documentation.
--
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
Please refer to https://github.com/php-fig/fig-standards/pull/169
This just adds another level of complication. FIG is not part of the
core PHP standards, and some of their choices simply don't fit with
legacy code. I suspect that some of the problems I'm currently hitting
are because the coding standards I follow do not match FIG ... and I
have no intentions of adding that to that todo list ... but I've paid
work to get on with currently before I can get back to documentation.
So put a strict no-upgrade-if-without-budget policy on whatever you're
working on then?
phpdocumentor is also not an "official" tool: it's built by volunteers and
outside the boundaries of php-src.
It's actually the PhpDocumentor folks (and Mike van Riel in first place)
pushing forward PSR-5: there's nothing more "official" than that right now.
That's the current standardization path.
Marco Pivetta
It's actually the PhpDocumentor folks (and Mike van Riel in first place)
pushing forward PSR-5: there's nothing more "official" than that right now.
That's the current standardization path.
docblock annotation has been the subject of RFC's as alternatives to
other annotation/typing options, and that is the correct platform to
carry out that debate rather than on third party tools/standards such as
fig and phpdocumentor. It is not only phdocumentor that uses docblock
material, the IDE's I use have no problem with the current docblock
material and so there has been no need until now to look at why only
phpdocumentor2 has a problem with them ...
--
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
It's actually the PhpDocumentor folks (and Mike van Riel in first place)
pushing forward PSR-5: there's nothing more "official" than that right
now.
That's the current standardization path.docblock annotation has been the subject of RFC's as alternatives to
other annotation/typing options, and that is the correct platform to
carry out that debate rather than on third party tools/standards such as
fig and phpdocumentor.
Yeap, and these RFCs were rejected due to the fact that for the purposes of
php-src it's just comments that can be read as strings via Reflection API.
It is not only phdocumentor that uses docblock
material, the IDE's I use have no problem with the current docblock
material and so there has been no need until now to look at why only
phpdocumentor2 has a problem with them ...
Most (all?) of those APIs/IDEs/tools are basing their implementation on
PHPDocumentor's documentation at
http://www.phpdoc.org/docs/latest/index.html, if not directly on
PHPDocumentor's components.
Not everything in PHP is specified by php-src, nor should be.
Actually, pretty much nothing in PHP userland is specified by php-src, and
it's probably for the best, since this way you get a choice.
In this case you have a simple choice:
- not upgrading a stable tool
- accepting that there are BC breaks due to the evolution of the ecosystem
in the past 10 years, and adapting an old codebase to 10 years of changes
Marco Pivetta
Coming from a background of 'traditional' php design, all of my code and
the libraries I use are documented via phpdoc style annotation which the
IDE picks up, and phpdocumentor1 produced a good API description. This
was also a GOOD basis to tidy up the various changes through PHP5.xToday much of the infrastructure to make that work is broken and
http://lsces.org.uk/wiki/bitweaver+documentation is a starting point at
getting the material all up to date. The original documentation had a
few errors on the log file, buthttp://lsces.org.uk/bwdocs2/index.html
is the version I've been working on and is listing 3300 errors in the
documentation! The next step is to work out how to address those errors,
Phpdocumentor2?
I don't remember the details, but a single patch cleaned up a ton of
errors for me. I googled the error message and found a github? pull
request or bug report. The best answer is at the bottom of the
discussion. As of the last time I loaded it, about 3 months ago, I
still had to apply the patch.
I am in favor of typed properties but it's actually a fairly low
priority for me. There are also several questions that need answering,
such as what happens when you type a property with type Foo
but
don't assign it a value in the constructor. Also, is the check
bypassed with inheritance when you don't call parent constructor?
Given that it's non-trivial (but not necessarily very complex) and
only a low priority I haven't taken the time to make a proposal. I am
instead focusing on union, sum and enum types.
De : Ryan Pallas [mailto:derokorian@gmail.com]
With all the new typing and strict mode in PHP7, I'm wondering if there is
any planned support for typing of properties in a future version. IE
something like:class Foo {}
class Bar {
public Foo $foo;public function __construct(Foo $foo) {
$this->foo = $foo;
}
}This seems really useful to me. If its not something that was considered
before I can try to write up an RFC for this, however I'm not sure if this
was already considered and denied. Any feedback would be greatly
appreciated.
Hi,
I proposed this as an addition to scalar type hinting when we were discussing the STH RFC some months ago. Zeev and Dmitry, like Rasmus today, thought it was probably not possible to implement it without huge changes to the engine. After thinking more about it, I think they're absolutely right. What you want to implement is not an additional compile-time check, it's attaching type hints to object properties. That's a runtime check and a possible conversion each time a property is assigned. The problem is that the current engine makes it impossible to trap every zval assignments, let alone the question of performance. If you look at parameter type hints, argument types are checked only once, when they are received by the function. Then, in the function body, you can assign any value/type to every received argument, that's impossible to check.
Rewriting your example to show the feature has nothing to do with compile-time checks :
public function __construct(Foo $foo) {
manage($foo);
$this->foo=$foo; /* Compile-time OK, Runtime error */
}
/* In another file, somewhere... */
public function manage(&$obj)
{
...
$obj='bar';
}
Regards
François
Maybe implement getter/setter as ECMAScript 6?
class Person
{
get name ():string { return $this._name }
set name (string $value) { $this._name = $value }
}
2015-07-14 11:05 GMT+02:00 S.A.N ua.san.alex@gmail.com:
Maybe implement getter/setter as ECMAScript 6?
class Person
{
get name ():string { return $this._name }
set name (string $value) { $this._name = $value }
}
Which was rejected some time ago. (34 vs 22 in favor):
https://wiki.php.net/rfc/propertygetsetsyntax-v1.2
Maybe it's time to reevaluate the proposal and see if a new
implementation could gather
more support.
Yes, I think the compiler could compile the expression
class Bar
{
public Foo $foo; // That is shorthand getter/setter...
}
to
class Bar
{
get foo():Foo {return $this->_foo};
set foo(Foo $obj) {$this->_foo = $obj};
}
On Tue, Jul 14, 2015 at 3:51 AM, Sebastian B.-Hagensen
sbj.ml.read@gmail.com wrote:
2015-07-14 11:05 GMT+02:00 S.A.N ua.san.alex@gmail.com:
Maybe implement getter/setter as ECMAScript 6?
class Person
{
get name ():string { return $this._name }
set name (string $value) { $this._name = $value }
}Which was rejected some time ago. (34 vs 22 in favor):
https://wiki.php.net/rfc/propertygetsetsyntax-v1.2Maybe it's time to reevaluate the proposal and see if a new
implementation could gather
more support.
I personally voted no on that proposal because of the proposed syntax
and semantics. However I do like the idea of getters and setters and
definitely prefer a Dart-like syntax (which is where ECMAScript
basically got its syntax).