var_dump of $array returns this :
array (size=3)
0 =>
object(frontend\models\Notifications)[101]
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=5)
'id' => int 1
'created_on' => string '2015-11-12 12:12:15' (length=19)
'user_id' => int 1
'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
'is_seen' => int 0
private '_oldAttributes' (yii\db\BaseActiveRecord) =>
array (size=5)
'id' => int 1
'created_on' => string '2015-11-12 12:12:15' (length=19)
'user_id' => int 1
'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
'is_seen' => int 0
private '_related' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
1 =>
object(frontend\models\Notifications)[108]
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=5)
'id' => int 2
'created_on' => string '2015-11-12 12:12:15' (length=19)
'user_id' => int 1
'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
'is_seen' => int 0
................................
................................
................................
But the json_encode($array) returns [{}, {}, {}]. What I attempted: Tried changing the character encoding of the whole database to utf8_general_ci.
The character encoding is utf8_general_ci for my table and so is for my 'text' column of the table. What could be the issue?
Syntax. The json_encode() function can return a string containing the JSON representation of supplied value. The encoding is affected by supplied options, and additionally, the encoding of float values depends on the value of serialize_precision.
The json_encode() function is used to encode a value to JSON format.
json_encode(mixed $value , int $flags = 0, int $depth = 512): string|false. Returns a string containing the JSON representation of the supplied value . If the parameter is an array or object, it will be serialized recursively.
JSON data structures are very similar to PHP arrays. PHP has built-in functions to encode and decode JSON data. These functions are json_encode() and json_decode() , respectively. Both functions only works with UTF-8 encoded string data.
The array you show has all the properties as private. this mean that this value are not available outside their class's scope.
you can look at this SO for some suggestion
Using json_encode on objects in PHP (regardless of scope)
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