"Sputnik" help  
Sputnik Help
ClassOf(<className>, <value>)

Description

Converts the specified value to the given class type. If the value is already an instance of the specified class, it returns it as is. If the value is an associative array, it creates a new instance of the specified class with variables initialized from the array keys and values.

Parameters

<className> The name of the class to convert the value into.
<value> The value to be converted into the specified class.

Return Value

Success: Returns the instance of the specified class with variables initialized from the specified value.
Failure: Returns null if the value cannot be converted to the specified class within the scope of this function.

Remarks

The ClassOf function is used to explicitly convert a value into an instance of the specified class. If the provided value is already an instance of the specified class, it is returned without modification. If the value is an associative array, it creates a new instance of the specified class with variables initialized from the array keys and values.

Related

Casting, IsVarClass, Class

Example

Example of usage:

class EntityKitty { }
my $a = array("cat" => "meow");
my $b = ClassOf("EntityKitty", $a);
printr $b;

// PRINTS
// entitykitty Class
// (
//     [cat] => meow
// )

Casting:

class EntityKitty { }
my $a = array("cat" => "meow");
my $b = (EntityKitty)$a;
printr $b;

// PRINTS
// entitykitty Class
// (
//     [cat] => meow
// )

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org