<?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

    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>
    </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 -->
   <classsynopsis class="class">
    <ooclass>
     <modifier>final</modifier>
     <classname>FFI\CData</classname>
    </ooclass>
   </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
-->
