dourun2990 2012-03-04 05:09 采纳率: 100%
浏览 24
已采纳

php动态添加字段而不先定义它们

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

  • 写回答

1条回答 默认 最新

  • dsxon40042 2012-03-04 05:24
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)