mirror of
https://github.com/php/presentations.git
synced 2026-03-24 15:42:33 +01:00
31 lines
986 B
XML
31 lines
986 B
XML
<slide title="Objects">
|
|
<blurb>
|
|
Objects represent singular instances of a specified class.
|
|
</blurb>
|
|
|
|
<blurb>To initialize an object instance, use the new keyword:</blurb>
|
|
<example type="php" title="new" fontsize="1.2em"><![CDATA[<?php
|
|
$obj = new Simple;
|
|
?>]]>
|
|
</example>
|
|
<blurb>If the class has a constructor, simply add your function
|
|
arguments to the classname:</blurb>
|
|
<example type="php" title="Constructor" fontsize="1.2em"><![CDATA[<?php
|
|
$obj = new Simple ('hallo world');
|
|
?>]]>
|
|
</example>
|
|
<blurb>To access object properties, use the '->' specifier:</blurb>
|
|
<example type="php" title="Properties" fontsize="1.2em"><![CDATA[<?php
|
|
$obj = &new Simple ('hallo world');
|
|
print $obj->someprop;
|
|
?>]]>
|
|
</example>
|
|
<blurb>To access object methods, you can also use the '->' specifier:</blurb>
|
|
<example type="php" title="Methods" fontsize="1.2em"><![CDATA[<?php
|
|
$obj = &new Simple ('hallo world');
|
|
print $obj->someprop . "\n<br>\n";
|
|
print $obj->somemethod ();
|
|
?>]]>
|
|
</example>
|
|
|
|
</slide> |