New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] PHP84 : Add spec compliance #74
base: 3.x
Are you sure you want to change the base?
Conversation
13f0140
to
5fbf4d4
Compare
c938d8c
to
2a0559f
Compare
2a0559f
to
74328c7
Compare
|
||
interface Loader | ||
{ | ||
public function __invoke(DOMDocument $document): void; | ||
public function __invoke(): XMLDocument; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO : document new API for loading DOM
8a61a7b
to
65810ed
Compare
65810ed
to
c5c3c5b
Compare
@@ -8,6 +8,8 @@ | |||
use XSLTProcessor; | |||
|
|||
/** | |||
* TODO : Add support for callables : https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl (either here or through a separate configurator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO : Add support
Just letting you know that while waiting for the reviews, I spent some time today implementing the missing APIs in a separate branch. (Can be found at nielsdos/php-src#93)
Fortunately, as expected, these were rather easy to implement. |
Cool! I'm a bit busy this week but will try to play around with it soon :) |
26d0875
to
644dd7d
Compare
Just wanted to give you a small update @nielsdos :
Getting closer to the end goal :) |
Thanks for the update! Nice to see ^^ I'll try to have a look soon-ish at how to deal with the As for the other issues: if you're stuck debugging them, I could always try to have a look at your code with a debug PHP build, if I know what test case to look for :) |
dd60a1d
to
4628c16
Compare
4628c16
to
5144ee2
Compare
5144ee2
to
518eac4
Compare
633b668
to
50a3e8e
Compare
50a3e8e
to
e066614
Compare
@nielsdos All unit tests are succeeding, which is nice. Next up - static analysis:
I'm using the stubs that are included in your PR which are not able to infer specific types in specific situations. What would be the best way forward there? Is it a matter of just fixing the provided stub files? Or should some kind of effort be needed in psalm ad well? How do you see the path forward there? (I know it' still very early for adding PHP 8.4 support - but I'm just asking to figure out what the next steps would be in that space.) |
Psalm has stubs built in, which they also further annotate with version information, e.g. https://github.com/vimeo/psalm/blob/5.x/stubs/extensions/dom.phpstub Can you share an example of a type inference error? |
I'm just gonna paste the full list of errors here so that you can skim around it - but that doesnt mean I expect answers for them ;) Reveal the errrors
|
At least some errors are legit, e.g. Some others, e.g. Some others are about nullability. So all in all, quite a few seem to be because of type changes.
This one is a "mistake" in the stub and you can fix it by copying the stub from the master branch. This was found already by one of the Symfony developers and fixed in master. What's going on here is that I didn't put a backslash before |
Stubs issues: @nielsdos I was fixing some psalm issues and was bumping against following issues:
documentURI is marked as readonly in the stubs but is not readonly:
If those are resolved, I think the rest of them are located inside my repository. Can you check these? |
Yeah this information should be put into psalm eventually.
Fixed in php/php-src#13982, good catch
This is, unfortunately, the right type.
This is also unfortunately possible. I.e.: https://3v4l.org/bsF7g/rfc#vgit.master |
In other news, I've been wrapping up the implementation work for the remaining features I wanted to add to ext-dom in PHP 8.4. One thing I'm having some difficulties with is the API design of The problem is as follows: I haven't been able to come up with a good solution. Here are some things I thought about:
I'm not sure how to go about it. Maybe you have some ideas. |
If I understand the problem correctly, then it's about some kind of transition from I'm a bit confused by the sentence:
This means that wether it returns a HTMLElement is based on a namespace URI like There are some ways to look at this:
Let's take a look at the provided solutions:
I'm not sure what properties you are talking about here - but I would say that switching type of node is not something you want to do here. So to me this is a no-go.
This is indeed not a good idea either. However I do like the idea of making it return the node you are renaming so that it can be chained. That's another discussion I suppose.
You mean leave it out of the HTMLElement class? This might be confusing since you are extending the regular Element and it would be there and throw an exception. It is still needed in regular Element though for various operations you can find in this repository, so not having it would be kinda blocking. Maybe some other ideas:
Cool, great work. I'm sure your work here will be viable in the long run! I do have some last thing I am thinking on and off about for some while now, maybe I'dd just ask here: Why do both To be clear, I don't want to add more work for you to the table since you are already doing so much. Let me know if I can help with anything. |
ea92150
to
a5f45a9
Compare
a5f45a9
to
ba8e0d7
Compare
@nielsdos Thanks for the review on the static analysis part. I was able to get it all covered now. |
Awesome! 🎉
Indeed
Yes
You are right about both these things: these are strange things to do. However, users have always managed to surprise me :-) I agree with your conclusions about the provided workarounds.
Yes, leave it out for HTMLElement for example. I think you're right this is strange though.
These seem like sensible solutions, I'm not sure though on how well this generalises and how well this would work for potential future DOM APIs (e.g. the
I don't know, ask my predecessors :-) It should not be hard to add though. I found two feature requests about this: https://bugs.php.net/bug.php?id=46146 and https://bugs.php.net/bug.php?id=63506
I easily see the use case for XMLWriter, it's often the case that XML is embedded into something, and with XMLWriter being stream-oriented it makes perfect sense to have an As for XMLReader, I find it harder to see the use case. You can use
Well, using existing resource types is fine, introducing new resource types is not. The stream resource will stay with us for some time anyway. |
What would be the benifit of having a registerElementClass? As-in : what does it solve? There are 2-3 ways to go in this case :
Nice :)
For example XML responses in HTTP Responses: Even in PSR-7, you could use a StreamWrapper to make sure you don't have to write to a file before reading this stream. It would be nice if one could just |
I was thinking about hypothetical future additions that could cause problems.
The first two bullet points are the most sensible in my opinion. I'll have another think about it. I'll also discuss this internally a bit more.
Please see nielsdos/php-src#106 When implementing this I dug into the libxml APIs and found that the underlying API allows setting a character encoding. So it's possible to extend the function signature to this:
Yeah okay that makes perfect sense, thanks. |
Wow that was fast 😮
Sure makes sense to add it. There is no option to do so at this moment, so makes sense!
That would indeed be a good API. (The I notice from my library, I did not implement encoding and flags - so might need to do that here as well. Maybe I'll also create some kind of libxml flag builder someday, cause those are confusing me everytime I look at them :) |
FWIW, after discussion internally about For XMLReader & XMLWriter, I can do a short RFC for this. I'll work on adding the encoding parameter too, it makes me wonder what the encoding is it uses right now actually or if it does some kind of autodetect... Of course the libxml docs aren't really helping here...
The options aren't always amazingly named. E.g. LIBXML_NOENT is my "favourite" one because people often think it stands for "NO ENtity substitution", but it does the opposite :-( |
FWIW, I made a draft RFC for the XMLReader&Writer openStream function: https://wiki.php.net/rfc/xmlreader_writer_streams. I'm sharing this with a few people and if nothing comes up I'll post it to the mailing list tomorrow evening or on Tuesday or so, I'll see. |
@nielsdos nice! Let's hope for a smooth acceptance path then :) |
Summary
A playground for the new spec-compliance RFC:
WIP: Extended DOM
Current stats:
TODO: