Class Spelling

When calling methods, it says “method not found”. What could be wrong?

<?php
class c_string
{
    public function __construct()
    {
        $this->content="";
    }
    public function append($_content)
    {
        $this->content.=$_content;
    }
};
class InstallForm extends c_string
{
    public function __construct()   
    {
        //$text.append("<table>");
        $this->text="<table>";
        //$content.append("");
        //$content.append("</table>");
    }
    function addElem($field_caption,$input_type,$input_value,$input_name)
    {
        //$text.append("<tr><td>$field_caption:</td><td><input type=\"$input_type\" value=\"$input_value\" name=\"$input_name\"></td></tr>");
        $this->text.=("<tr><td>$field_caption:</td><td><input type=\"$input_type\" value=\"$input_value\" name=\"$input_name\"></td></tr>");
    }
    public function End()
    {
        $this->text.=("</table>");
        return $this->text;
    }
};
$tmp  = new InstallForm();
$tmp.addElem("sadsa","text","sdfdsf","test1");
$tmp.addElem("sadsa","text","sdfdsf","test1");
$tmp.addElem("sadsa","text","sdfdsf","test1");
echo $tmp.End();
?>

Answer 1, authority 100%

In PHP you should do this:

$tmp  = new InstallForm();
$tmp->addElem("sadsa","text","sdfdsf","test1");
$tmp->addElem("sadsa","text","sdfdsf","test1");
$tmp->addElem("sadsa","text","sdfdsf","test1");
echo $tmp->End();

The object model resembles Java, but the syntax is different


Answer 2, authority 50%

$tmp  = new InstallForm();
$tmp->addElem("sadsa","text","sdfdsf","test1");
$tmp->addElem("sadsa","text","sdfdsf","test1");
$tmp->addElem("sadsa","text","sdfdsf","test1");
echo $tmp->End();

You are calling incorrectly. And yet, I have never seen that they put ; at the end of the class, although this also works.

Leave a reply

Please enter your comment!
Please enter your name here