2

When using php library for RTM (https://github.com/bartosz-maciaszek/php-rtm), I am getting a response for a particular tasks-list like this:

[notes] => Rtm\DataContainer Object

(
    [attributes:Rtm\DataContainer:private] => Array
        (
            [note] => Rtm\DataContainer Object
               (
                   [attributes:Rtm\DataContainer:private] => Array
                       (
                           [id] => 56254802
                           [created] => 2016-11-06T10:46:43Z
                           [modified] => 2016-11-06T10:49:26Z
                           [title] => null
                           [$t] => https://stackoverflow.com/questions/910912/extract-urls-from-text-in-php1
                       )

               )

        )

)

I can get the value of id, created, modified just fine but $t doesn't work.

$note_obj = $obj->getNotes()->getNote();
$note_id = $note_obj->getId();
echo "$note_id\n";  //works fine

$note_content = $note_obj->get{'$t'}(); //doesn't work
print_r($note_content); 

Obviously $note_obj->get{'$t'}; fails here.....So How do I access such data?

Khurshid Alam
  • 209
  • 1
  • 3
  • 10
  • try `$note_obj->{'get$t'}();` – Dekel Nov 06 '16 at 15:38
  • @Dekel Nope. That didn't work either. `PHP Fatal error: Uncaught BadMethodCallException: Method get$t not implemented in https://github.com/bartosz-maciaszek/php-rtm/blob/master/src/Rtm/DataContainer.php`.....looking at [DataContainer.php](https://github.com/bartosz-maciaszek/php-rtm/blob/master/src/Rtm/DataContainer.php) I found a method which converts object to array. May be that's the way to go. I will try and comment here. – Khurshid Alam Nov 06 '16 at 17:30
  • Try `var_dump(get_class_methods($note_obj));` to see if you have any specific methods you can use to get all the values. – Dekel Nov 06 '16 at 17:35
  • Wow!...it worked....Awesome thanks for pointing me to right direction. – Khurshid Alam Nov 06 '16 at 17:36
  • which solution? :) – Dekel Nov 06 '16 at 17:37
  • `var_dump(get_class_methods($note_obj)); ` gives me something like `{ string(7) "toArray" [9]=> string(6) "toJson" } ` I used toArray to convert to array. – Khurshid Alam Nov 06 '16 at 17:40
  • great :) so I guess you used the `toArray` function? – Dekel Nov 06 '16 at 17:42
  • Yes. I put a answer. Thanks. :) – Khurshid Alam Nov 06 '16 at 17:50

1 Answers1

0

I found out all methods of classes are handled by DataContainer.php which has a method like toArray to convert the object into array.

These methods can also be exposed by (as pointed out by @Dekel in the comment):

var_dump(get_class_methods($note_obj)); gives

array(10) {
[0]=>
string(11) "__construct"
[1]=>
string(11) "getIterator"
[2]=>
string(5) "count"
[3]=>
string(6) "__call"
[4]=>
string(3) "get"
[5]=>
string(3) "set"
[6]=>
string(3) "has"
[7]=>
string(6) "remove"
[8]=>
string(7) "toArray"
[9]=>
string(6) "toJson"
}

And hence the code is:

$note_obj = $obj->getNotes()->getNote();
$rtm_item_note_content = $note_obj->toArray();
$rtm_item_note_content = $rtm_item_note_content['$t'];
echo "note content: $rtm_item_note_content\n";

Done!

Khurshid Alam
  • 209
  • 1
  • 3
  • 10