<?php
class getData {
public $myArray = array();
function __construct() {
array_push($this->myArray,"cat");
array_push($sths->myArray,"dog");
}
}
$p = new getData();
var_dump($p->myArray);
Fatal error: Uncaught Error: Attempt to modify property "myArray" on null in /in/QTtWH:9
Stack trace:
#0 /in/QTtWH(13): getData->__construct()
#1 {main}
thrown in /in/QTtWH on line 9
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: Creating default object from empty value in /in/QTtWH on line 9
Warning: array_push() expects parameter 1 to be array, null given in /in/QTtWH on line 9
array(1) {
[0]=>
string(3) "cat"
}
Warning: array_push(): First argument should be an array in /in/QTtWH on line 9
array(1) {
[0]=>
string(3) "cat"
}
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QTtWH on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QTtWH on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/QTtWH on line 5
Process exited with code 255.