dongtui8593 2013-01-12 23:44
浏览 51

引用时,私有变量返回空白,尽管它是在函数中设置的

I have a class to create forms and a function that gets the form name form action and form type from the view files. It works fine and as expected, but when I call those variables in another function to create the actual form and to add the values to the they return as blank.

class Form {
     private $formname;
     private $formaction;
     private $formtype;

function Form($form_name, $actionfile, $formtype) {
            $this->formname = $form_name;
            $this->formaction = $actionfile;
            $this->formtype = $formtype;
        }

This is where the functions values get stored in the private variables.

When I try to call them in another function they return as blank.

function formstart() {
$enc = 'enctype="multipart/form-data"';
$returnstring = '<form name="' . $this->formname . '" id="' . $this->formname . '" ' . $enc . ' method="' . $this->formtype . '"  action="' . $this->formaction . '">';
}

Am I missing something ?

  • 写回答

2条回答 默认 最新

  • dsfds2353 2013-01-12 23:47
    关注

    Your class must be namespaced to use that constructor function. Instead, use the method __construct()

    class Form {
         private $formname;
         private $formaction;
         private $formtype;
    
        function __construct($form_name, $actionfile, $formtype) {
            $this->formname = $form_name;
            $this->formaction = $actionfile;
            $this->formtype = $formtype;
        }
    }
    

    Documentation

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了