downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/language.types.object.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/language.types.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'language.types.object.php',
   
1 => 'Objects',
  ),
 
'up' =>
  array (
   
0 => 'language.types.php',
   
1 => 'Types',
  ),
 
'prev' =>
  array (
   
0 => 'language.types.array.php',
   
1 => 'Arrays',
  ),
 
'next' =>
  array (
   
0 => 'language.types.resource.php',
   
1 => 'Resources',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="language.types.object" class="sect1">
 <h2 class="title">Objects</h2>

 <div id="language.types.object.init" class="sect2">
  <h3 class="title">Object Initialization</h3>

  <p class="para">
   To create a new <a href="language.types.object.php" class="type object">object</a>, use the <i>new</i> statement
   to instantiate a class:
  </p>

  <div class="informalexample">
   <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">foo<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">do_foo</span><span style="color: #007700">()<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Doing&nbsp;foo."</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">do_foo</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <p class="simpara">
   For a full discussion, see the
   <a href="language.oop5.php" class="link">Classes and Objects</a> chapter.
  </p>

 </div>
 
 <div id="language.types.object.casting" class="sect2">
  <h3 class="title">Converting to object</h3>
 
  <p class="para">
   If an <a href="language.types.object.php" class="type object">object</a> is converted to an <a href="language.types.object.php" class="type object">object</a>, it is not
   modified. If a value of any other type is converted to an
   <a href="language.types.object.php" class="type object">object</a>, a new instance of the <i>stdClass</i>
   built-in class is created. If the value was <b><tt class="constant">NULL</tt></b>, the new instance will be
   empty. <a href="language.types.array.php" class="type Array">Array</a>s convert to an <a href="language.types.object.php" class="type object">object</a> with properties
   named by keys, and corresponding values. For any other value, a member
   variable named <i>scalar</i> will contain the value.
  </p>

  <div class="informalexample">
   <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$obj&nbsp;</span><span style="color: #007700">=&nbsp;(object)&nbsp;</span><span style="color: #DD0000">'ciao'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">scalar</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;outputs&nbsp;'ciao'<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

 </div>
</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites