NYCPHP Meetup

NYPHP.org

[nycphp-talk] For Dan - per request

soazine at pop.erols.com soazine at pop.erols.com
Mon Oct 6 14:17:49 EDT 2003


STEPS I FOLLOWED IN PURSUIT OF ORIGINAL PROBLEM 10/6/2003 @ 1:30AM EST
----------------------------------------------------------------------------
---------------------------------

http://us2.php.net/manual/en/ref.classobj.php 

Highlight:



Example 2. test_script.php

<pre>
<?php

include "classes.inc";

// utility functions

function print_vars($obj) {
    $arr = get_object_vars($obj);
    while (list($prop, $val) = each($arr))
        echo "\t$prop = $val\n";
}

function print_methods($obj) {
    $arr = get_class_methods(get_class($obj));
    foreach ($arr as $method)
        echo "\tfunction $method()\n";
}

function class_parentage($obj, $class) {
    global $$obj;
    if (is_subclass_of($$obj, $class)) {
        echo "Object $obj belon

gs to class ".get_class($$obj);
        echo " a subclass of $class\n";
    } else {
        echo "Object $obj does not belong to a subclass of $class\n";
    }
}

// instantiate 2 objects

$veggie = new Vegetable(true,"blue");
$leafy = new Spinach();

// print out information about objects
echo "veggie: CLASS ".get_class($veggie)."\n";
echo "leafy: CLASS ".get_class($leafy);
echo ", PARENT ".get_parent_class($leafy)."\n";

// show veggie properties
echo "\nveggie: Properties\n";
print_vars($veggie);

// and leafy methods
echo "\nleafy: Methods\n";
print_methods($leafy);

echo "\nParentage:\n";
class_parentage("leafy", "Spinach");
class_parentage("leafy", "Vegetable");
?>
</pre>

One important thing to note in the example above is that the object $leafy
is an instance of the class Spinach which is a subclass of Vegetable,
therefore the last part of the script above will output:

[...]
Parentage:
Object leafy does not belong to a subclass of Spinach
Object leafy belongs to class spinach a subclass of Vegetable


-------------------------------------------------------------------------
(incidentally, I DID just that in my subclass to reference the superclass'
method: $cartQuery = $this->display_cart();
-------------------------------------------------------------------------

http://www.phpbuilder.com/manual/keyword.extends.php

-------------------------------------------------------------------------

http://www.zend.com/zend/zengine/zengine-issue10.php (based upon a
comp.lang.php newsgroup article I thought would maybe clarify the SYNTAX of
calling a superclass method from a subclass using the Namespace operator -
was wrong there!)

-------------------------------------------------------------------------

http://groups.google.com/groups?hl=en&lr=&ie=ISO-8859-1&q=class+extends&btnG
=Google+Search&meta=group%3Dcomp.lang.php

Couldn't find anything there other than the typical denotation
$this->super_class_method() 

-------------------------------------------------------------------------

http://www.pcoms.net/

That was suggested by Dan Horning.  I found nothing there that pertained to
my problem.

-------------------------------------------------------------------------

There you have it.  As you can see I followed the steps to the letter in
searching out the problem on my own, which was to no avail at the time,
hence, my decision to brainlessly post on nyphp.org my apparently inane
questions about classes and calling the superclass method from the subclass.

I hope that offers proof of my ability to follow instruction.

Phil



--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .





More information about the talk mailing list