Return to Snippet

Revision: 20801
at November 24, 2009 21:47 by chrisaiv


Updated Code
<?php

class Person
{
	function say_hello(){
		echo "Yo Yo Yo";
	}	
}

/*
//Reveal all the classes that have been defined including what PHP does by default
$classes = get_declared_classes();
foreach( $classes as $class ){
	echo $class . "<br />";
}
*/

if( class_exists("Person") ){
	echo "That class has been defined.<br />";
} else {
	echo "Class not defined!<br />";
}

$methods = get_class_methods('Person');
foreach($methods as $method){
	echo $method;
}

if(method_exists('Person', 'say_hello')){
	echo "method does exist";
} else {
	echo "Method does not exist";
}
?>

Revision: 20800
at November 24, 2009 21:43 by chrisaiv


Initial Code
<?php

class Person
{
	
}

/*
//Reveal all the classes that have been defined including what PHP does by default
$classes = get_declared_classes();
foreach( $classes as $class ){
	echo $class . "<br />";
}
*/

if( class_exists("Person") ){
	echo "That class has been defined.<br />";
} else {
	echo "Class not defined!<br />";
}

?>

Initial URL


Initial Description


Initial Title
PHP: Determine if a Class has been defined

Initial Tags
php

Initial Language
PHP