2019-05-05 16:06:46 +00:00
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
<!-- $Revision$ -->
|
|
|
|
|
|
|
|
|
|
<phpdoc:classref xml:id="class.ffi-cdata" xmlns:phpdoc="http://php.net/ns/phpdoc" 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
|
2019-06-01 12:09:20 +00:00
|
|
|
|
|
2019-05-05 16:06:46 +00:00
|
|
|
|
PHP data:
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2019-06-01 12:09:20 +00:00
|
|
|
|
C data of scalar types can be read and assigned via the <property>$cdata</property> property, e.g.
|
|
|
|
|
<code>$x = FFI::new('int'); $x->cdata = 42;</code>
|
2019-05-05 16:06:46 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
C struct and union fields can be accessed as regular PHP object property, e.g.
|
|
|
|
|
<code>$cdata->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 regualar comparison operators (<code><</code>,
|
|
|
|
|
<code><=</code>, <code>==</code>, <code>!=</code>, <code>>=</code>, <code>></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>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
|
|
|
|
Noteable 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 -->
|
|
|
|
|
<classsynopsis>
|
|
|
|
|
<ooclass><classname>FFI\CData</classname></ooclass>
|
|
|
|
|
|
|
|
|
|
<!-- {{{ Class synopsis -->
|
|
|
|
|
<classsynopsisinfo>
|
|
|
|
|
<ooclass>
|
|
|
|
|
<classname>FFI\CData</classname>
|
|
|
|
|
</ooclass>
|
|
|
|
|
</classsynopsisinfo>
|
|
|
|
|
<!-- }}} -->
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
|
|
|
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.ffi-cdata')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])">
|
|
|
|
|
<xi:fallback />
|
|
|
|
|
</xi:include>
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
</classsynopsis>
|
|
|
|
|
<!-- }}} -->
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</partintro>
|
|
|
|
|
|
|
|
|
|
<!-- &reference.ffi.entities.ffi-cdata; -->
|
|
|
|
|
|
|
|
|
|
</phpdoc:classref>
|
|
|
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
|
-->
|