doufei1852 2014-09-17 15:10
浏览 31
已采纳

attr_accessor从ruby到php

I am tying to convert a ruby code into php, from scratch. I have a few questions:

1.how would look the attr_accessor :ID :code in php? Something like this? private $ID=null; private $code=null;

  1. how would look the code in php for: def initialize(attributes={}) self.ID = attributes[:ID] self.CODE = attributes[:code]

Hope you can help, Kind regards, jhonnatan

Edited: 3. def get_ID get('get_ID') end

Will it be something like this: public function __construct(ID) get('...')

  • 写回答

1条回答 默认 最新

  • doudonglu3764 2014-09-17 15:17
    关注

    PHP equivalent for

    1 - attr_accessor :ID and def get_ID get('get_ID') end

    private $ID;
    
    public function setID($ID)
    {
        $this->ID = $ID;
    }
    
    public function getID() // This is the equivalent for def get_ID get('get_ID') end
    {
        return $this->ID;
    }
    

    2 - def initialize(attributes={})

    public function __construct($attributes)
    {
        $this->ID = $attributes['ID'];
        $this->code = $attributes['code'];
    
    }
    

    3 - def myFunction ... end

    public function myFunction() // If it's inside a class if not remove public
    {
        ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM