I want to add a function on an object that returns a specific value from that object.
I have the following code now:
<?php
namespace sdk;
use core\Sdk;
class Contents extends Sdk {
public $url;
public $id;
public function __call($method, $args) {
if (isset($this->$method)) {
$func = $this->$method;
return call_user_func_array($func, $args);
}
}
public function getContents($id = '') {
$request = 'contents/list/'.$id;
return $this->getRequest($request);
}//getContents
public function getContent($id) {
$request = 'contents/detail/'.$id;
$this->object = $this->getRequest($request);
$this->object->getItemAttribute = function($attribute) {
var_dump($this->object);
};
return $this->object;
}//getContent
}//Class Contents
and I try to start the method via tis code
$contents->getContent(1);
$contents->object->getItemAttribute('titel');
But I keep getting the error "undefined method"
What am I doing wrong?