Im new to Objects and have some basic understanding, but struggling with getting data from a particular type of node.
This:
$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 i can get the ID by doing:
$test->broadcast_data->id
But how do i get the linked_children
array and assign it to a variable. The colon and slashes in "data":"threewp_broadcast\broadcast_data":private
is throwing me off.
Thanks
The name of the property is data
. The colons and slashes that you're seeing is not part of the property of the class.
"data":"threewp_broadcast\broadcast_data":private
The threewp_broadcast\broadcast_data
represents the namespace and class that the property belongs to and the :private
means that the data
property is private
, therefore you cannot access it without a class method.
You can look in the class file to see if there's a function like getData()
which would return the value of the private property.
For example, a class like the following:
namespace A;
class B{
private $test;
}
And the dump of it would give the following:
object(A\B)#1 (1) {
["test":"A\B":private]=>
NULL
}
As you can see "test":"A\B":private
is not the name of the property.
After looking in the class threewp_broadcast\broadcast_data, there is a function named getData()
so you could do:
$test->broadcast_data->getData()['linked_children'];
Or simply use the function get_linked_children()
provided by the class:
$test->broadcast_data->get_linked_children();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With