D语言:你如何做Php array(); 的foreach()?

3 php d

我怎么能正确地将这个$ array和$ object和foreach()从Php解释为D?

Php(亲):

class Zend_Models
{
    public static function getSome()
    {
      $array = array(
         "a" => "b",
         "b" => "b"
      );
      $object = (object) $array;

      foreach($object as $value)
      {
        $this->view->inject[] = $value;              
      }
      // Zend_Debug::dump($this->view->inject); 
      return "ok";
    }


    public static getAbove() 
    {
      return self::getSome();
    }
}
Run Code Online (Sandbox Code Playgroud)

D(孵化器,做错误):

import std.stdio;

class Zend_Models
{
  void static getSome()
  {
    //?...
  }
}
Run Code Online (Sandbox Code Playgroud)

dsi*_*cha 5

我认为这样做会:

import std.stdio;

class Zend_Models
{
    string getSome()
    {
          auto array = ["a", "b"];

          foreach(value; array)
          {
              this.view.inject ~= value;
          }

          return "ok";
       } 
    }

    string getAbove() {
        return getSome();
    }
}
Run Code Online (Sandbox Code Playgroud)

也就是说,您可能不应该尝试在D中编写PHP.使用异常可能比返回状态代码更好,如果确实返回状态代码,则枚举可能比字符串更好.