Php adding fields on the fly without defining them first

so in php you do not define the field in the class, first as java, is this true?

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 documentation? and what is the correct term for this behavior, I don’t think it is called adding a field on the fly

+7
source share
1 answer

You're right. You can assign a value to an uninitialized property in PHP. Java is strict and PHP is loose goosey :)

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

+6
source

All Articles