Jump to content

Loading class


MeTitus

Recommended Posts

Hi guys,

 

Basically I have this in a xml document:

 

        <handler class="Registration" procedure="web_userLogin" />

 

the web_userLogin is a static method in Registration, the problem is that I don't know how to load the class.

I was having this as reference but I wasn't yet able to succeed.

 

[reference]

 

PHP 5 is very very flexible in accessing member variables and member functions. These access methods maybe look unusual and unnecessary at first glance; but they are very useful sometimes; specially when you work with SimpleXML classes and objects. I have posted a similar comment in SimpleXML function reference section, but this one is more comprehensive.

 

I use the following class as reference for all examples:

<?

class Foo {

    public $aMemberVar = 'aMemberVar Member Variable';

    public $aFuncName = 'aMemberFunc';

 

 

    function aMemberFunc() {

        print 'Inside `aMemberFunc()`';

    }

}

 

$foo = new Foo;

?>

 

You can access member variables in an object using another variable as name:

<?

$element = 'aMemberVar';

print $foo->$element; // prints "aMemberVar Member Variable"

?>

 

or use functions:

<?

function getVarName()

{ return 'aMemberVar'; }

 

print $foo->{getVarName()}; // prints "aMemberVar Member Variable"

?>

 

Important Note: You must surround function name with { and } or PHP would think you are calling a member function of object "foo".

 

you can use a constant or literal as well:

<?

define(MY_CONSTANT, 'aMemberVar');

print $foo->{MY_CONSTANT}; // Prints "aMemberVar Member Variable"

print $foo->{'aMemberVar'}; // Prints "aMemberVar Member Variable"

?>

 

You can use members of other objects as well:

<?

print $foo->{$otherObj->var};

print $foo->{$otherObj->func()};

?>

 

You can use mathods above to access member functions as well:

<?

print $foo->{'aMemberFunc'}(); // Prints "Inside `aMemberFunc()`"

print $foo->{$foo->aFuncName}(); // Prints "Inside `aMemberFunc()`"

 

[/reference]

 

Any help is more than welcome,

 

Thanks,

 

MeTitus

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.