PHP code example of rumd3x / php-baseobject

1. Go to this page and download the library: Download rumd3x/php-baseobject library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rumd3x / php-baseobject example snippets


use Rumd3x\BaseObject\BaseObject;

class MyClass extends BaseObject {
    // Your class definition
    private $my_property;
}

$obj = new MyClass;
$obj->my_property = 'value'; 
// This will automatically do $obj->setMyProperty('value'); if you have defined this method. 

$prop_value = $obj->my_property; 
// This will automatically do $prop_value = $obj->getMyProperty(); if you have defined this method. 

$obj = new MyClass;

// BaseObject::parse($data) Creates a new instance base on the contents of $data.
// Data can be either an object of any class, an array, a json string or a XML string.
MyClass::parse($data); // Returns instance of MyClass.
$obj->parse($data); // Casts $data into the already existing instance.


$obj->toArray(); // Converts the object to an array.
$obj->toJson(); // Converts the object to a json string representation.
$obj->toXml(); // Converts the object to a XML string representation.

// You can also safely use the object to along side with strings.
echo $obj;
$string = "my object value => {$obj}";