1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00
Files
archived-doc-en/reference/ffi/ffi.cdata.xml

166 lines
4.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<reference xml:id="class.ffi-cdata" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>C Data Handles</title>
<titleabbrev>FFI\CData</titleabbrev>
<partintro>
<!-- {{{ FFI\CData intro -->
<section xml:id="ffi-cdata.intro">
&reftitle.intro;
<para>
<classname>FFI\CData</classname> objects can be used in a number of ways as a regular
PHP data:
<itemizedlist>
<listitem>
<simpara>
C data of scalar types can be read and assigned via the <property>$cdata</property> property, e.g.
<code>$x = FFI::new('int'); $x-&gt;cdata = 42;</code>
</simpara>
</listitem>
<listitem>
<simpara>
C struct and union fields can be accessed as regular PHP object property, e.g.
<code>$cdata-&gt;field</code>
</simpara>
</listitem>
<listitem>
<simpara>
C array elements can be accessed as regular PHP array elements, e.g.
<code>$cdata[$offset]</code>
</simpara>
</listitem>
<listitem>
<simpara>
C arrays can be iterated using &foreach; statements.
</simpara>
</listitem>
<listitem>
<simpara>
C arrays can be used as arguments of <function>count</function>.
</simpara>
</listitem>
<listitem>
<simpara>
C pointers can be dereferenced as arrays, e.g. <code>$cdata[0]</code>
</simpara>
</listitem>
<listitem>
<simpara>
C pointers can be compared using regular comparison operators (<code>&lt;</code>,
<code>&lt;=</code>, <code>==</code>, <code>!=</code>, <code>&gt;=</code>, <code>&gt;</code>).
</simpara>
</listitem>
<listitem>
<simpara>
C pointers can be incremented and decremented using regular <code>+</code>/<code>-</code>/
<code>++</code>/<code>--</code> operations, e.g. <code>$cdata += 5</code>
</simpara>
</listitem>
<listitem>
<simpara>
C pointers can be subtracted from another using regular <code>-</code> operations.
</simpara>
</listitem>
<listitem>
<simpara>
C pointers to functions can be called as a regular PHP closure, e.g. <code>$cdata()</code>
</simpara>
</listitem>
<listitem>
<simpara>
Any C data can be duplicated using the <link linkend="language.oop5.cloning">clone</link>
operator, e.g. <code>$cdata2 = clone $cdata;</code>
</simpara>
</listitem>
<listitem>
<simpara>
Any C data can be visualized using <function>var_dump</function>, <function>print_r</function>, etc.
</simpara>
</listitem>
<listitem>
<simpara>
<classname>FFI\CData</classname> can now be assigned to structs and fields as of PHP 8.3.0.
</simpara>
</listitem>
</itemizedlist>
<note>
<simpara>
Notable limitations are that <classname>FFI\CData</classname> instances do not support
<function>isset</function>, <function>empty</function> and <function>unset</function>,
and that wrapped C structs and unions do not implement <interfacename>Traversable</interfacename>.
</simpara>
</note>
</para>
</section>
<!-- }}} -->
<section xml:id="ffi-cdata.synopsis">
&reftitle.classsynopsis;
<!-- {{{ Synopsis -->
<packagesynopsis>
<package>FFI</package>
<classsynopsis class="class">
<ooclass>
<modifier>final</modifier>
<classname>CData</classname>
</ooclass>
</classsynopsis>
</packagesynopsis>
<!-- }}} -->
</section>
<section role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
<classname>FFI\CData</classname> can now be assigned to structs and fields.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</section>
</partintro>
<!-- &reference.ffi.entities.ffi-cdata; -->
</reference>
<!-- 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
-->