Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

cvs: phpdoc /en/reference/classobj/functions class-exists.xml
aidan		Sat Sep 25 05:06:38 2004 EDT

Modified files:
/phpdoc/en/reference/classobj/functions	class-exists.xml
Log:
Added simple example
Cleaned initial example
Added links to autoload

http://cvs.php.net/diff.php/phpdoc/...1.5&r2=1.6&ty=u
Index: phpdoc/en/reference/classobj/functions/class-exists.xml
diff -u phpdoc/en/reference/classobj/functions/class-exists.xml:1.5 phpdoc/e
n/reference/classobj/functions/class-exists.xml:1.6
--- phpdoc/en/reference/classobj/functions/class-exists.xml:1.5	Thu Jul  1 2
3:07:07 2004
+++ phpdoc/en/reference/classobj/functions/class-exists.xml	Sat Sep 25 05:06
:35 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.5 $ -->
+<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/classobj.xml, last change in rev 1.11 -->
<refentry id="function.class-exists">
<refnamediv>
@@ -8,26 +8,37 @@
</refnamediv>
<refsect1>
<title>Description</title>
-     <methodsynopsis>
-      <type>bool</type><methodname>class_exists</methodname>
-      <methodparam><type>string</type><parameter>class_name</parameter></me
thodparam>
-      <methodparam choice="opt"><type>bool</type><parameter>autoload</param
eter></methodparam>
-     </methodsynopsis>
-    <note>
-     <para>
-      The <parameter>autoload</parameter> parameter was added in PHP 5
-     </para>
-    </note>
+    <methodsynopsis>
+     <type>bool</type><methodname>class_exists</methodname>
+     <methodparam><type>string</type><parameter>class_name</parameter></met
hodparam>
+     <methodparam choice="opt"><type>bool</type><parameter>autoload</parame
ter></methodparam>
+    </methodsynopsis>
<para>
This function returns &true; if the class given by
<parameter>class_name</parameter> has been defined,
&false; otherwise.
</para>
<para>
-    <function>class_exists</function> will attempt to call __autoload by
-    default, if you don't want <function>class_exists</function> to
-    call __autoload(), you can set the parameter <parameter>autoload</param
eter>
-    to &false;.
+     <example>
+      <title><function>class_exists</function> example</title>
+      <programlisting role="php">
+<![CDATA[
+<?php
+// Check the class exists before trying to use it
+if (class_exists('MyClass')) {
+    $myclass = new MyClass();
+}
+
+?>
+]]>
+      </programlisting>
+     </example>
+    </para>
+    <para>
+     <function>class_exists</function> will attempt to call &link.autoload;
 by
+     default, if you don't want <function>class_exists</function> to
+     call &link.autoload;, you can set the parameter <parameter>autoload</p
arameter>
+     to &false;.
</para>
<para>
<example>
@@ -35,26 +46,33 @@
<programlisting role="php">
<![CDATA[
<?php
-    function __autoload($class) {
-        include($class . '.php');
+function __autoload($class)
+{
+    include($class . '.php');

-        /* Check to see it the include defined the class */
-        if ( !class_exists($class, false) ) {
-           trigger_error("Unable to load class $class", E_USER_ERROR);
-        }
+    // Check to see if the include declared the class
+    if (!class_exists($class, false)) {
+        trigger_error("Unable to load class: $class", E_USER_WARNING);
}
+}

-    if( class_exists('MyClass') ) {
-        $myclass = new MyClass();
-    }
+if (class_exists('MyClass')) {
+    $myclass = new MyClass();
+}

?>
]]>
</programlisting>
</example>
</para>
+    <note>
+     <para>
+      The <parameter>autoload</parameter> parameter was added in PHP 5
+     </para>
+    </note>
<simpara>
-     See also <function>get_declared_classes</function>.
+     See also <function>interface_exists</function>, and
+     <function>get_declared_classes</function>.
</simpara>
</refsect1>
</refentry>

Report this thread to moderator Post Follow-up to this message
Old Post
Aidan Lister
09-25-04 01:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Documentation archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.