Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php adding field on the fly without defining them first

so in php, you don't have define the field in a class first like java , is that correct??

in java you cannot say

public class javac {
    int x;
    int y;
    public javaC() {
     this.z = 3;
    }
 }

but in php can you say that?

class phpC {
$x;
$y;

public phpC() {
   $this->z = "omg"; 
 }
  }

what is php's documentation on this? and what is the correct term for such behaviour, i dont think it is called adding field on the fly

like image 663
user1118019 Avatar asked Mar 04 '12 05:03

user1118019


1 Answers

You are correct.. You can assign a value to an uninitialized property in PHP. Java is strict and PHP is loosey goosey :)

The technical name for this is "overloading." Here is the documentation: http://php.net/manual/en/language.oop5.overloading.php

like image 110
James L. Avatar answered Oct 16 '22 00:10

James L.