diff options
| author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-10-11 16:41:07 +0200 |
|---|---|---|
| committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-10-29 15:58:32 +0100 |
| commit | 64685782e4a811e2a210aa91208be998e7f853ca (patch) | |
| tree | 70ded5da80c081313a1343160d8cd880d08bdf7d /ext/xmlreader/tests | |
| parent | 4963701aa4b70c97d8cc0b7803f09958f0809a07 (diff) | |
| download | php-git-64685782e4a811e2a210aa91208be998e7f853ca.tar.gz | |
Allow to call XMLReader::open() and ::XML() statically
The implementation of `XMLReader::open()` and `XMLReader::XML()` still
supports calling the methods statically and non-statically. However,
as of PHP 8.0.0, calling these methods statically is not allowed,
because they are not declared as static methods. Since we consider it
to be cleaner to call these methods statically, but had deprecated to
call them statically, we properly support both variants.
We implement support for static and non-static calls by overloading, so
that non-static calls have access to the `$this` pointer.
Diffstat (limited to 'ext/xmlreader/tests')
| -rw-r--r-- | ext/xmlreader/tests/static.phpt | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/xmlreader/tests/static.phpt b/ext/xmlreader/tests/static.phpt new file mode 100644 index 0000000000..0218efd5fc --- /dev/null +++ b/ext/xmlreader/tests/static.phpt @@ -0,0 +1,33 @@ +--TEST-- +Calling XMLReader::open() and ::XML() statically +--SKIPIF-- +<?php +if (!extension_loaded("xmlreader")) die('skip xmlreader extension not available'); +?> +--FILE-- +<?php +$filename = __DIR__ . '/static.xml'; + +$xmlstring = '<?xml version="1.0" encoding="UTF-8"?> +<books></books>'; +file_put_contents($filename, $xmlstring); + +$reader = XMLReader::open($filename); +while ($reader->read()) { + echo $reader->name, "\n"; +} + +$reader = XMLReader::XML($xmlstring); +while ($reader->read()) { + echo $reader->name, "\n"; +} +?> +--EXPECTF-- +books +books +books +books +--CLEAN-- +<?php +unlink(__DIR__ . '/static.xml'); +?> |
