看不懂,你哪里生出个$screen->setServlet($action);你这样设计类不好吧?

解决方案 »

  1.   

    扫了一眼``~~发现你这个写错了public function _construct(){
    是__construct,两横的~~
      

  2.   

    对不起,昨天代码没有贴好:
    class Action{
    function doAction(){
    print("test");
    }
    }
    class Temp{
    private $action;
    private $html;

    public function _construct(){
    }

    function getAction(){
    return $this->$action;
    }
    function getHtml(){
    return $this->$html;
    } function setAction($_action){
    $this->$action = $_action;
    }
    function setHtml($_html){
    $this->$html = $_html;
    }
    }class Config{ function getName($name){
    $Temp = new Temp();
    $action = new Action();
    $html = 2;
        $screen->setAction($action);
    $screen->setTemplate($html);
    return $temp;
    }
    }
    class A{
       function execute(){
          $config = new Config();
          $aa = "random";
          $tt = $config->getName($aa);
          print($tt->getAction());
       }
    }
      

  3.   

    function _construct()你这个还是没有改~~~
      

  4.   

    function _construct()已经改过来了
    function __construct()
      

  5.   

    function getName($name)???这个$name参数有什么用?在你的类的方法里这个参数根本没用到~~莫名其妙
      

  6.   

    我现在没有用到$name这个参数,因为我程序没有写完,我现在只是在做测试。但就可运行的程序来看,temp类中的两个内部成员变量指向了同一个内存地址,而在其他代码中没有出现这样的情况。我很奇怪。希望能得到帮助
      

  7.   

    代码不全!
    $screen在哪里实例化的?
      

  8.   

    对不起,代码还是没有给好,config代码如下
    class Config{ function getName($name){
    $Temp = new Temp();
    $action = new Action();
    $html = 2;
                      $Temp->setAction($action);
    $Temp->setTemplate($html);
    return $temp;
    }
    }
      

  9.   

    Fatal error: Call to undefined method Temp::setTemplate()
      

  10.   

    晕啊!
    class Config{ function getName($name){
    $Temp = new Temp();
    $action = new Action();
    $html = 2;
                      $Temp->setAction($action);
    $Temp->setHtml($html);
    return $temp;
    }
    }
      

  11.   

    www.phpe.net多去看一些PHP5的关于OO的文章!你写的这个类,不要也罢
      

  12.   

    to: lins(Anders*小明)贴你的全部代码好吗?你给几个类有什么用啊?你是怎么调用的?你的测试代码呢?
      

  13.   

    okay, I had solve it myself. It's due to my fault that I write "$this->$html" to access class members, but "$this->html" is correct. 
    Thanks all guys. Thank you for your paying attention to this.to  surfchen(冲浪) :
      OOD is a solutions and methods set to help we to build a system. Every languages has its spec to implements those. In this issue, it's a solecism that I made. In the case of I write a new class to replace it, It will still not work. But thanks you all same.
      

  14.   

    There is the answer:
    The variable is named $cart->items, not $cart->$items, that is, a variable name in PHP has only a single dollar sign. <?php
    // correct, single $
    $cart->items = array("10" => 1); // invalid, because $cart->$items becomes $cart->""
    $cart->$items = array("10" => 1);// correct, but may or may not be what was intended:
    // $cart->$myvar becomes $cart->items
    $myvar = 'items';
    $cart->$myvar = array("10" => 1);  
    ?>  
      

  15.   

    There is the Cart class
    class Cart {
       var $todays_date;
       var $name;
       var $owner;
       var $items = array("VCR", "TV");   function Cart() {
           $this->todays_date = date("Y-m-d");
           $this->name = $GLOBALS['firstname'];
           /* etc. . . */
       }
    }