Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Basic Methods

Frank Kleine edited this page May 1, 2013 · 3 revisions

Applies to versions < 3.0.0 only

Nearly every class in Stubbles implements the net\stubbles\lang\Object interface. This allows to have some common methods for simple operations on objects, e.g. comparing via equals($compare) and basic object-to-string conversion via __toString().

In Stubbles two base classes implementing this interface exist: net\stubbles\lang\BaseObject and net\stubbles\lang\exception\Exception. While the latter one is the base class of all exceptions in Stubbles the former one is used as base class for all other classes except noted otherwise.

There is one exception from the rule. All classes in Stubbles extending built-in PHP classes will not implement this interface as well to prevent naming conflicts with existing methods in those built-in PHP classes. However it is possible that some of the methods are implemented without implementing the whole interface. We strive to always have a __toString() and an equals($compare) method in every class which allows to create an instance of it.

getClass()

This method will return an instance of net\stubbles\lang\reflect\ReflectionObject (see reflection docs for more information about the extended reflection classes). This allows a simpler approach to inspect the object.

getClassName()

This method returns the full qualified class name as a string.

hashCode()

This method returns a unique identifier for any instance of an object. The default implementations available in net\stubbles\lang\BaseObject and net\stubbles\lang\exception\Exception rely on the spl_object_hash() function`.

equals($compare)

This method allows to compare any value to the class instance. The default implementations available in net\stubbles\lang\BaseObject and net\stubbles\lang\exception\Exception return true if $compare is an instance of the same class and both instance have the same hash code.

__toString()

This method allows an automatic conversion of the object instance into a string. See PHP manual for more details.

The result is a short but informative representation about the class and its values. Per default, this method returns:

[fully-qualified-class-name] ' {' [members-and-value-list] '}'

An example:

example\MyClass {
    foo(string): hello
    bar(example\AnotherClass): example\AnotherClass {
        baz(int): 5
    }
}

This notation says that the instance of the example\MyClass class has a property foo of type string with the value hello, and a property named bar of type example\AnotherClass which itself has a property named baz of type integer with value 5.

The result for exceptions in Stubbles is a bit differant:

example\MyException {
    message(string): This is an exception.
    file(string): /path/to/file.php
    line(integer): 4
    code(integer): 3
}
Clone this wiki locally