I've begun dabbling in OOP in PHP a little, but have run into a few problems that I unfortunately don't have a good enough grasp of PHP OOP to fully understand yet. So hopefully someone can help me see the light.
My code is below:
class MyClass
{
function MyClass($flag)
{
if (!$flag)
print("Hello World");
else
print("The flag '" . $flag . "', was passed.<br><br>\n");
}
}
$cls01 = new MyClass("coredump");
if ($cls01)
print("Object exists!\n");
else
print("Object doesn't exist. :(\n");
Running the script seems to work, but not quite. It detects the argument to the constructor fine... but doesn't seem to create the object itself. The output for the above script is below:
The flag 'coredump', was passed.
Object doesn't exist. :(
So, the argument is passed properly, but despite this... the object is not created. Any ideas why?
Furthermore, I've tried retrieving a value from $_GET in an attempt to pass it to the constructor, but that code hangs on me as well:
var $myFlag;
if ($GET['flag'])
$myFlag = $GET['flag'];
else
$myFlag = null;
class MyClass
{
function MyClass($flag)
{
if (!$flag)
print("Hello World");
else
print("The flag '" . $flag . "', was passed.<br><br>\n");
}
}
$cls01 = new MyClass($myFlag);
if ($cls01)
print("Object exists!\n");
else
print("Object doesn't exist. :(\n");
... but this code doesn't even provide the output the script above does. Just gives a blank screen. Any ideas why this might be happening?
Thanx,