Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions reference/simplexml/simplexmlelement/current.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="simplexmlelement.current" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>SimpleXMLElement::current</refname>
<refpurpose>Returns the current element</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="SimpleXMLElement">
<modifier>public</modifier> <type>SimpleXMLElement</type><methodname>SimpleXMLElement::current</methodname>
<void/>
</methodsynopsis>

<warning>
<simpara>
Prior to PHP 8.0, <methodname>SimpleXMLElement::current</methodname> was only
declared on the subclass <classname>SimpleXMLIterator</classname>.
</simpara>
</warning>

<para>
This method returns the current element as a <classname>SimpleXMLElement</classname> object.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the current element as a <classname>SimpleXMLElement</classname> object.
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<para>
Throws an <classname>Error</classname> on failure.
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>
An <classname>Error</classname> is now thrown if
<methodname>SimpleXMLElement::current</methodname> is called on an
invalid iterator. Previously, &null; was returned.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Return the current element</title>
<programlisting role="php">
<![CDATA[
<?php
$xmlElement = new SimpleXMLElement('<books><book>PHP basics</book><book>XML basics</book></books>');
var_dump($xmlIElement->current());

$xmlElement->rewind(); // rewind to first element
var_dump($xmlElement->current());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
NULL
object(SimpleXMLElement)#2 (1) {
[0]=>
string(10) "PHP basics"
}
]]>
</screen>
</example>
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>SimpleXMLElement::key</methodname></member>
<member><methodname>SimpleXMLElement::next</methodname></member>
<member><methodname>SimpleXMLElement::rewind</methodname></member>
<member><methodname>SimpleXMLElement::valid</methodname></member>
<member><classname>SimpleXMLElement</classname></member>
</simplelist>
</para>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="simplexmliterator.getchildren" xmlns="http://docbook.org/ns/docbook">
<refentry xml:id="simplexmlelement.getchildren" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>SimpleXMLIterator::getChildren</refname>
<refname>SimpleXMLElement::getChildren</refname>
<refpurpose>Returns the sub-elements of the current element</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>SimpleXMLIterator</type><methodname>SimpleXMLIterator::getChildren</methodname>
<methodsynopsis role="SimpleXMLElement">
<modifier>public</modifier> <type class="union"><type>SimpleXMLElement</type><type>null</type></type><methodname>SimpleXMLElement::getChildren</methodname>
<void/>
</methodsynopsis>

<warning>
<simpara>
Prior to PHP 8.0, <methodname>SimpleXMLElement::getChildren</methodname> was only
declared on the subclass <classname>SimpleXMLIterator</classname>.
</simpara>
</warning>

<para>
This method returns a <classname>SimpleXMLIterator</classname> object
containing sub-elements of the current <classname>SimpleXMLIterator</classname>
This method returns a <classname>SimpleXMLElement</classname> object
containing sub-elements of the current <classname>SimpleXMLElement</classname>
element.
</para>
</refsect1>
Expand All @@ -26,7 +34,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a <classname>SimpleXMLIterator</classname> object containing
Returns a <classname>SimpleXMLElement</classname> object containing
the sub-elements of the current element.
</para>
</refsect1>
Expand All @@ -49,9 +57,9 @@ $xml = <<<XML
</books>
XML;

$xmlIterator = new SimpleXMLIterator($xml);
for( $xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
foreach($xmlIterator->getChildren() as $name => $data) {
$xmlElement = new SimpleXMLElement($xml);
for ($xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {
foreach($xmlElement->getChildren() as $name => $data) {
echo "The $name is '$data' from the class " . get_class($data) . "\n";
}
}
Expand All @@ -61,16 +69,15 @@ for( $xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
&example.outputs;
<screen>
<![CDATA[
The title is 'PHP Basics' from the class SimpleXMLIterator
The author is 'Jim Smith' from the class SimpleXMLIterator
The title is 'PHP Basics' from the class SimpleXMLElement
The author is 'Jim Smith' from the class SimpleXMLElement
]]>
</screen>
</example>
</para>
</refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="simplexmliterator.haschildren" xmlns="http://docbook.org/ns/docbook">
<refentry xml:id="simplexmlelement.haschildren" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>SimpleXMLIterator::hasChildren</refname>
<refname>SimpleXMLElement::hasChildren</refname>
<refpurpose>Checks whether the current element has sub elements</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>SimpleXMLIterator::hasChildren</methodname>
<methodsynopsis role="SimpleXMLElement">
<modifier>public</modifier> <type>bool</type><methodname>SimpleXMLElement::hasChildren</methodname>
<void/>
</methodsynopsis>

<warning>
<simpara>
Prior to PHP 8.0, <methodname>SimpleXMLElement::hasChildren</methodname> was only
declared on the subclass <classname>SimpleXMLIterator</classname>.
</simpara>
</warning>

<para>
This method checks whether the current <classname>SimpleXMLIterator</classname> element has sub-elements.
This method checks whether the current <classname>SimpleXMLElement</classname> element has sub-elements.
</para>
</refsect1>

Expand Down Expand Up @@ -46,10 +54,10 @@ $xml = <<<XML
</books>
XML;

$xmlIterator = new SimpleXMLIterator( $xml );
for( $xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
if($xmlIterator->hasChildren()) {
var_dump($xmlIterator->current());
$xmlElement = new SimpleXMLElement($xml);
for ($xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {
if ($xmlElement->hasChildren()) {
var_dump($xmlElement->current());
}
}
?>
Expand All @@ -58,7 +66,7 @@ for( $xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
&example.outputs;
<screen>
<![CDATA[
object(SimpleXMLIterator)#2 (2) {
object(SimpleXMLElement)#2 (2) {
["title"]=>
string(10) "PHP Basics"
["author"]=>
Expand All @@ -71,7 +79,6 @@ object(SimpleXMLIterator)#2 (2) {
</refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
Expand Down
119 changes: 119 additions & 0 deletions reference/simplexml/simplexmlelement/key.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="simplexmlelement.key" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>SimpleXMLElement::key</refname>
<refpurpose>Return current key</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="SimpleXMLElement">
<modifier>public</modifier> <type>string</type><methodname>SimpleXMLElement::key</methodname>
<void/>
</methodsynopsis>

<warning>
<simpara>
Prior to PHP 8.0, <methodname>SimpleXMLElement::key</methodname> was only
declared on the subclass <classname>SimpleXMLIterator</classname>.
</simpara>
</warning>

<para>
This method gets the XML tag name of the current element.
</para>

</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the XML tag name of the element referenced by the current <classname>SimpleXMLElement</classname> object.
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<para>
Throws an <classname>Error</classname> on failure.
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>
An <classname>Error</classname> is now thrown if
<methodname>SimpleXMLElement::key</methodname> is called on an
invalid iterator. Previously, &false; was returned.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Get the current XML tag key</title>
<programlisting role="php">
<![CDATA[
<?php
$xmlElement = new SimpleXMLElement('<books><book>PHP basics</book><book>XML basics</book></books>');

echo var_dump($xmlElement->key());
$xmlElement->rewind(); // rewind to the first element
echo var_dump($xmlElement->key());

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(false)
string(4) "book"
]]>
</screen>
</example>
</para>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
Loading