Getting data from a PHP object using colonies and pigtails in a name

Im new to objects and has some basic understanding, but struggles with getting data from a specific node type.

It:

$test->broadcast_data

Returns:

object(threewp_broadcast\BroadcastData)#1599 (5) {
  ["id"]=>
  int(49663)
  ["blog_id"]=>
  int(1)
  ["post_id"]=>
  int(38863)
  ["dataModified":"threewp_broadcast\broadcast_data":private]=>
  bool(true)
  ["data":"threewp_broadcast\broadcast_data":private]=>
  array(2) {
    ["version"]=>
    int(2)
    ["linked_children"]=>
    array(3) {
      [2]=>
      int(18557)
      [3]=>
      int(8097)
      [4]=>
      int(1768)
    }
  }
}

I know that I can get the identifier by doing:

$test->broadcast_data->id

But how do I get an array linked_childrenand assign it to a variable. The colon and slashes "data":"threewp_broadcast\broadcast_data":privatecast me away.

thank

+4
source share
1 answer

The name of the property data. The colons and slashes you see are not part of the class property.

"data":"threewp_broadcast\broadcast_data":private

threewp_broadcast\broadcast_datarepresents the namespace and the class to which the property belongs, and :privatemeans that the property data private, so you cannot access it without the class method.

, , getData(), .

, :

namespace A;

class B{
    private $test;   
}

:

object(A\B)#1 (1) {
  ["test":"A\B":private]=>
  NULL
}

, "test":"A\B":private .

Update

threewp_broadcast\broadcast_data getData(), :

$test->broadcast_data->getData()['linked_children'];

get_linked_children(), :

$test->broadcast_data->get_linked_children();
+6

Source: https://habr.com/ru/post/1693331/


All Articles