java - troubles with variables in PHP -
i new in php java background. in confusion next code:
class pupil { //public $name; public function __construct($name) { $this->name=$name; } public function showname() { echo $this->name; } }
on above code if comment line public $name;
still works. however, in java not supposed work. want understand behavior in php.
php uses implicit declaration of properties. can declare , assign property anywhere (even outside class).
<?php $object1 = new user(); $object1->name = "alice"; echo $object1->name; class user {} ?>
would work fine , print "alice"...
java php
No comments:
Post a Comment