Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well,</p> <p>What you are wanting to do sounds really good on paper, and you want code to be maintainable, and depending on your actual system, what you ask may even be somewhat safe, however it's getting close to being dangerous and error prone.</p> <p>Anyway, you would probably have to do most of this yourself, or just insert some sort of interceptor to all method calls, here's a quick example:</p> <pre><code>class Book { public $title = ''; public $id = 0; public function setTitle($string) { $this-&gt;title = $string; echo "title called with $string\n"; } public function twoArgs($arg1,$arg2) { echo "Multi-call: $arg1,$arg2\n"; } } class Api { public function parse($json) { $jsonobj = json_decode($json,true); foreach ($jsonobj as $key=&gt;$value) { $class_name = $key; $obj = new $class_name(); foreach ($value as $vkey=&gt;$vvalue) { if (method_exists($obj,$vkey)) { call_user_func_array(array($obj,$vkey),$vvalue); } else if (isset($obj-&gt;$vkey)) { echo "Setting $vkey\n"; $obj-&gt;$vkey = $vvalue; } } } } } $json = json_encode(array('Book' =&gt; array('id' =&gt; 1234, 'setTitle' =&gt; array('The new title')))); $api = new Api(); $api-&gt;parse($json); $json = json_encode(array('Book' =&gt; array('id' =&gt; 1234, 'twoArgs' =&gt; array('arg1 :) ', 'arg2 :]')))); $api-&gt;parse($json); </code></pre> <p>Obviously you'd want to add in logic to handle persist flagging, and loading or allow them to pass in a constructor: [args] and handle that. etc. When it comes to exposing functions, you expose them in documentation, they are all accessible as long as they are public functions from that point on etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload