On 20/06/2024 23:55, Matthew Weier O'Phinney wrote:
> 
> 
> On Thu, Jun 20, 2024, 1:27 PM Niels Dossche <dossche.ni...@gmail.com 
> <mailto:dossche.ni...@gmail.com>> wrote:
> 
>     On 20/06/2024 16:28, Matthew Weier O'Phinney wrote:
>     >
>     >
>     > On Mon, Jun 10, 2024 at 1:15 PM Niels Dossche <dossche.ni...@gmail.com 
> <mailto:dossche.ni...@gmail.com> <mailto:dossche.ni...@gmail.com 
> <mailto:dossche.ni...@gmail.com>>> wrote:
>     >
>     >     Hi internals
>     >
>     >     I'm opening the vote of my RFC "New ext-dom features in PHP 8.4".
>     >     RFC link: https://wiki.php.net/rfc/dom_additions_84 
> <https://wiki.php.net/rfc/dom_additions_84> 
> <https://wiki.php.net/rfc/dom_additions_84 
> <https://wiki.php.net/rfc/dom_additions_84>>
>     >     Voting runs until 24th of June 21:00 GMT+2.
>     >
>     >     Kind regards
>     >     Niels
>     >
>     >
>     > Question: why is `Dom\Document::$head` marked as readonly?
> 
>     The HTML spec defines the head property to be readonly: 
> https://html.spec.whatwg.org/#document 
> <https://html.spec.whatwg.org/#document>
>     That's why $head is marked readonly.
> 
>     So I guess the question becomes "why does the HTML spec define it this 
> way?"
>     I couldn't find a conclusive answer to this, it looks like this has been 
> read-only since HTML's early days...
>     I thought about it but don't really see a technical reason why this is 
> the case. If I had to take a guess I'd say it's for simplicity sake.
>     > he/him
> 
> 
> I can understand that from a browser perspective, but from PHP, where we 
> might be manipulating HTML to send back to the client, having it readonly 
> would be a pretty big hindrance. 
> 

Would it?
Note that only the binding is readonly, you can manipulate the head element as 
you wish.
e.g. `$doc->head->replaceWith($another_element);` is still possible and not 
much more difficult than `$doc->head = $another_element;`.

I could add a setter for the head element, but what if WHATWG defines a setter 
for the head element at a later point in time that's incompatible with what I 
added?
It may sound far-fetched, but that's not unreasonable given that setting the 
$body property is way more complicated than just find+replace `<body>` (e.g. 
handles framesets too).

Kind regards
Niels

Reply via email to