Why do I get this 'Undefined variable' PHP error?

<?php
class Student {

}
$student1 = new Student;

$student2 = new Student;

echo get_class($student1) . "<br />";
echo get_class($student2);

$class_names = ['Product', 'Student', 'student'];
foreach ($class_names as $classname) {
	if(is_a($student1, $class_name)) {
		echo "{$class_name} is a declared class. <br>";
	}else {
		echo "{$class_name} is a not a declared class. <br>";
	}
}

I am getting this error. why so? can some one guide me please?

Take a careful look at the code you have written. The error message tells you what the problem is.

I just copied from lynda.com. they do not have

error.

their code is different to yours.

everything.php (393 Bytes)

How different?

An underscore.

Tip: if you get an error message about an undefined variable/property/index the absolute first thing to do is to check for typos.

1 Like

Look where you defined $class_name.

1 Like

Ahhhh got it. Thanks. Wow code is running now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.