1
0
mirror of https://github.com/php/php-src.git synced 2026-04-30 03:33:17 +02:00

447 Commits

Author SHA1 Message Date
Tim Düsterhus 7114314c5a tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an
unnecessary layer of indirection.
2026-04-28 22:12:56 +02:00
Jordi Kroon 9498bc3ee1 fix Dom\Notation nodes missing tree connection
Fixes an existing TODO by @ndossche.

Notation nodes returned from $doctype->notations were not linked to their owning document or parent DocumentType. This caused several incorrect behaviour; including:

ownerDocument was missing
parentNode was NULL
isConnected returned false
baseURI fell back to "about:blank"
textContent returned an empty string instead of NULL

The last point is a violation of the DOM specification. Since Notation is not an Element, CharacterData, Attr, or DocumentFragment, its textContent must return NULL.

Spec reference: https://dom.spec.whatwg.org/#dom-node-textcontent

close GH-21868
2026-04-25 20:13:14 +01:00
David CARLIER 2945c72a14 build/gen_stub: support asymmetric visibility modifiers. (#21773)
Emit ZEND_ACC_PUBLIC_SET / PROTECTED_SET / PRIVATE_SET from the
corresponding Modifiers::*_SET flags in generated arginfo, gated
to PHP 8.4+ where asymmetric visibility was introduced. Previously
private(set) and friends in stubs parsed without error but produced
no set-visibility flag.

@readonly on DOM property stubs was documentation only and did not
translate to any runtime flag, so reflection reported the properties
as writable while the write_property handler threw on assignment.
Declaring them public private(set) lets the engine reject external
writes via the normal visibility check and lets ReflectionProperty::
isWritable() answer honestly.

After converting virtual properties from @readonly to private(set),
dom_write_property still threw a readonly-modification error. Since
the handler replaces zend_std_write_property, the engine's own
asymmetric-visibility check is bypassed on the write path, so the
DOM handler now raises it explicitly via
zend_asymmetric_visibility_property_modification_error() when the
caller lacks set access. The readonly error is kept as a fallback.
2026-04-18 16:47:59 +01:00
Ben Ramsey cf23c1e80e license-update: ext/dom source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Gina Peter Banyard ce1761e3fe ext/dom: add a const qualifier in dom_objects_set_class_ex()(#21511) 2026-03-24 17:09:20 +00:00
Nurzhan Bazhirov b843e03c83 Zend: Remove unused parameter from zend_dval_to_lval_cap()
The `zend_string *s` parameter became unused after commit f754ffa8b2
(GH-20746) removed the `zend_oob_string_to_long_error()` calls.

This fixes an unused-parameter compiler warning and updates a stale
comment in zend_operators.c that incorrectly stated this function
can emit warnings.

Closes GH-21112
2026-02-04 15:25:42 +01:00
Niels Dossche f0f28b763c Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
2026-02-03 18:41:13 +01:00
Niels Dossche 52eb174ba6 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
2026-02-03 18:40:54 +01:00
Niels Dossche b8fc6bd1c8 Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
Split the handler again, or defer to instanceof when performance doesn't
matter.

Closes GH-21108.
2026-02-03 18:36:28 +01:00
Niels Dossche 0f4f73a254 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
2026-01-30 18:14:24 +01:00
Niels Dossche d54e5106b0 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
2026-01-30 18:14:19 +01:00
Niels Dossche d73b2f782e Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
Prior to this patch there was a common read handler, and it relied on
the dom class set in the intern document. However, Dom\Implementation
allows creating DTDs unassociated with a document, so we can't rely on
an intern document and the check fails. This causes the ZVAL_NULL() path
to be taken.
To solve this, just split the handler.

Closes GH-21082.
2026-01-30 18:13:55 +01:00
Niels Dossche b6f786a7ca Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20722: Null pointer dereference in DOM namespace node cloning via clone on malformed objects
2025-12-18 22:40:19 +01:00
Niels Dossche 735f354ac9 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20722: Null pointer dereference in DOM namespace node cloning via clone on malformed objects
2025-12-18 22:40:12 +01:00
Niels Dossche bf63341f35 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-20722: Null pointer dereference in DOM namespace node cloning via clone on malformed objects
2025-12-18 22:39:57 +01:00
Niels Dossche 983be089c0 Fix GH-20722: Null pointer dereference in DOM namespace node cloning via clone on malformed objects
Closes GH-20730.
2025-12-18 22:39:35 +01:00
Niels Dossche 7fbf9b8164 Merge branch 'PHP-8.5'
* PHP-8.5:
  Add forgotten NEWS item
  Partially fix GH-16317: DOM classes do not allow __debugInfo() overrides to work
2025-10-13 18:45:40 +02:00
Niels Dossche 599078f70b Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Add forgotten NEWS item
  Partially fix GH-16317: DOM classes do not allow __debugInfo() overrides to work
2025-10-13 18:45:34 +02:00
Niels Dossche 39ef16a496 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Partially fix GH-16317: DOM classes do not allow __debugInfo() overrides to work
2025-10-13 18:44:57 +02:00
Niels Dossche 8e0504c38b Partially fix GH-16317: DOM classes do not allow __debugInfo() overrides to work
Closes GH-20132.
2025-10-13 18:43:24 +02:00
Niels Dossche 44af9adf79 Drop LIBXML_HTML_ENABLED checks (#20083)
It is possible to build libxml without HTML support, which would mean
that PHP does not support the saveHtml() features and HTML parsing in
general. It also adds some maintenance complexity. I'm not aware of any
distro that does this and it shows: this has been broken since stubs
have been introduced. So we can just drop it as clearly no one cares
about this or we would've known about it already. It also simplifies
downstream code because they can now rely on the HTML functionality to
always be available.
2025-10-08 17:32:30 +02:00
Gina Peter Banyard b4ed215299 core: Warn when non-representable floats are coerced to int (#19760)
RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int
2025-09-21 23:53:16 +01:00
Niels Dossche 542712099f Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix naming clash with libxml macro
2025-09-14 16:40:47 +02:00
Ruoyu Zhong 8774e96bd4 Fix naming clash with libxml macro
In the macOS 26 SDK, xmlFree is defined as a macro for free. This causes
issues where a same-named variable is used. Renaming the variable to
should_free resolves the issue.

See:

    $ grep -B4 -A2 -n "#define xmlFree(" "Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.sdk/usr/include/libxml/globals.h"
    261-#if defined(LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS)
    262-#define xmlMalloc(size) malloc(size)
    263-#define xmlMallocAtomic(size) malloc(size)
    264-#define xmlRealloc(ptr, size) realloc((ptr), (size))
    265:#define xmlFree(ptr) free(ptr)
    266-#define xmlMemStrdup(str) strdup(str)
    267-#endif

Fixes:
```
    In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/xmlIO.h:117,
                    from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/parser.h:813,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/php_dom.h:29,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:26:
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c: In function 'dom_compare_value':
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:208:17: error: called object 'free' is not a function or function pointer
      208 |                 xmlFree(attr_value);
          |                 ^~~~~~~
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:204:14: note: declared here
      204 |         bool free;
          |              ^~~~
    make: *** [ext/dom/attr.lo] Error 1
```

Closes GH-19832.

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-09-14 16:40:22 +02:00
Niels Dossche a2d65354a0 dom: Rename get_named_item -> get_ns_named_item, and has_named_item -> has_ns_named_item 2025-07-11 12:29:29 +02:00
Niels Dossche e013b4a91e Make cloning DOM node lists, maps, and collections fail
This never worked and creates a broken object,
and on master can cause a crash with foreach.
It makes no sense to fix a behaviour that never worked, block it
instead.

Closes GH-19089.
2025-07-11 10:34:25 +02:00
Niels Dossche c7c6a79bd0 Add support for ParentNode::$children (#18908)
ParentNode::$children returns a HTMLCollection of all directly
descendant child elements of a container.

I had to move around some properties such that the ParentNode property
offsets are always at a fixed offset, to simplify the code.
This also adds the necessary code to deal with GC cycles in
HTMLCollections.
Furthermore, we also disable cloning a HTMLCollection as that never
worked and furthermore it also conflicts with the [[SameObject]] WebIDL
requirement of $children.
2025-06-27 09:03:50 +02:00
DanielEScherzer 171501b93f Replace @deprecated with #[\Deprecated] for internal constants (#18780)
Only covers constants declared via stub files, others will be handled
separately in a later commit.

Does not include the intl extension, since that had some errors relating to the
cpp code; that extension will be updated separately.
2025-06-26 11:27:15 -07:00
Niels Dossche 479e9be45d Store hash table entry directly in dom_nnodemap_object
Splits the purpose of the baseobj_zv: now no longer either is an array
or an object. Stores the hash table pointer directly, if used.
2025-06-22 12:30:50 +02:00
Niels Dossche 8526de84a5 Move common obj_map API functions to obj_map.c 2025-06-22 12:30:50 +02:00
Niels Dossche ff0a2cff05 Refactor implementation of DOM nodelists, named maps, and iterators
The code was really messy with lots of checks and inconsistencies.
This splits everything up into different functions and now everything is
relayed to a handler vtable.
2025-06-21 22:17:33 +02:00
Niels Dossche 4fadf647d2 Refactor dom_nnodemap_objects_new()
- Use ecalloc() to not miss initializing any field.
- Merge declarations and assignments.
2025-06-21 22:17:33 +02:00
Niels Dossche 307ff3bdea Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18744: PHP 8.4 classList works not correctly if copy HTMLElement by clone keyword.
2025-06-04 18:59:21 +02:00
Niels Dossche 111072a9f0 Fix GH-18744: PHP 8.4 classList works not correctly if copy HTMLElement by clone keyword.
The $classList property is special in the sense that it's a cached
object instance per (HTML)Element instance. The reason for this design
is because it has the [[SameObject]] IDL attribute.
Cloning in PHP also clones the properties, so it also clones the cached
instance. To solve this, we undo this by resetting the backing storage.

Closes GH-18749.
2025-06-04 18:59:05 +02:00
Máté Kocsis 7f59fccd52 Create separate lexbor extension (#18538)
An always enabled lexbor extension is added, containing the lexbor library that was separated from ext/dom extension in preparation of https://wiki.php.net/rfc/url_parsing_api. While at it, the lexbor library is upgraded to 2.5.0.

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2025-05-25 14:12:44 +02:00
Niels Dossche 3ba725a556 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:42 +02:00
Niels Dossche a019fbd970 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:12 +02:00
Niels Dossche ba0853888d Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
For dynamic fetches the cache_slot will be NULL, so we have to check for
that when resetting the cache. For zip and xmlreader this couldn't
easily be tested because of a lack of writable properties.

Closes GH-18307.
2025-04-11 23:33:58 +02:00
Niels Dossche 632357b275 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17991: Assertion failure dom_attr_value_write
2025-03-07 22:43:48 +01:00
Niels Dossche 6083dc09a3 Fix GH-17991: Assertion failure dom_attr_value_write
Closes GH-17995.
2025-03-07 22:43:38 +01:00
Niels Dossche d95b9d6d32 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:41:21 +01:00
Niels Dossche ee4a9a4a7c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:37:07 +01:00
Niels Dossche ce8ab5f16a Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00
Niels Dossche e6f42c1ed0 Fix incorrect casts 2025-01-11 10:50:07 +01:00
Niels Dossche 6cbe2edaad Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17397: Assertion failure ext/dom/php_dom.c
2025-01-08 19:46:23 +01:00
Niels Dossche 6d215981b6 Fix GH-17397: Assertion failure ext/dom/php_dom.c
The problem was that the property hash tables were not merging the
correct ones, a stupid typo (or caused by merging).

Closes GH-17406.
2025-01-08 19:45:40 +01:00
Niels Dossche 7be3649016 Cleanup iterator instantiation code (#17358)
Just using object_init_ex() directly makes the code a bit simpler and
avoids unnecessary indirections.
2025-01-04 16:48:41 +01:00
Niels Dossche 49fa2e4651 Make some arguments of dom_get_elements_by_tag_name_ns_raw() const 2025-01-03 17:50:01 +01:00
Niels Dossche 59a0d00a5d Avoid string duplications in dom iterators 2025-01-03 17:50:01 +01:00
Niels Dossche c015242947 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17145: DOM memory leak
2024-12-14 12:12:52 +01:00