致命错误:在非对象上调用成员函数getHTMLString() [英] Fatal error: Call to a member function getHTMLString() on a non-object
问题描述
我是OO PHP的新手,这可能是非常愚蠢的东西,我在redirect.php中有以下代码:
[PHP]<?php
include(include_functions.php);
include(classes.xhtml.php);
include(" classes.forms。 php");
error_reporting(E_ALL);
ini_set(''display_errors'',True);
//设置XHTML文档对象
$ htmlDoc = new XHTMLDocument("","","","");
//添加DocType
$ DocType = new DocumentType(" XHTMLTransitional");
$ htmlDoc-> setDocumentType($ DocType);
//添加头元素
$ headElement = new Head(",",",""," ;");
//标题元素
$ titleElement =新标题("","","","" ,"",""," theDDHut paypal redirec ");
$ headElement-> setTitleElement($ titleElement);
//添加脚本元素
$ jScriptElement =新脚本(" text / javascript","","",""," form_submission.js","","");
$ headElement-> addScriptElement($ jScriptElement);
// body元素
$ bodyElement = new Body(""," ","","","","","","","","",""," ","","","","","","","","",""," ","","","","","","");
// $ bodyElement = new Body( "","","","","","","","","","" ;, "","","","" ;,"",""," SubmitHiddenForm()","""",""""""""", "","","" ,","");
//添加身体的所有部分,表格是唯一的部分
if( isset($ _ POST))
{
$ formElement = new Form(GetPayPalURL()," POST","",""," ","","","","","","","","",""," ","","");
foreach($ _ POST为$ i => $ value)
{
$ inputField = new输入(","","","",""""""""""""" ,","" hidden",$ value e,"","","",""""""""", "");
$ formElement-> addElement($ inputField);
}
$ bodyElement-> addElement($ formElement);
}
$ htmlDoc-> setBodyElement($ bodyElement);
echo($ HTMLDOC - > getHTMLString());
?> [/ PHP]
然后在classes.xhtml.php中我有以下两个相关的类,但它几乎可以用于任何课程。
[PHP]
// ************** ***********************************
//姓名:文件类型
//目的:代表一个xhtml doctype对象
// ***************************** ****************
class DocumentType
{
private $ m_sDocType ="" ;;
// ********************************** ***********
//初始化程序
// ****************** *******************************
公共职能__construct($ type)
{
开关($ type)
{
case" HTMLStrict":
$ m_sDocType =" <!DOCTYPE HTML PUBLIC \" - // W3C // DTD HTML 4.01 // EN \" \" http://www.w3.org/TR/html4/strict.dtd\">" ;;
break;
case" ; HTMLTransitional":
$ m_sDocType ="<!DOCTYPE HTML PUBLIC \" - // W3C // DTD HTML 4.01 Transitional // EN \" \http://www.w3.org/TR/html4/loose.dtd\">" ;;
break;
case" ; HTMLFrameset":
$ m_sDocType ="<!DOCTYPE HTML PUBLIC \" - // W3C // DTD HTML 4.01 Frameset // EN \" \http://www.w3.org/TR/html4/frameset.dtd\">" ;;
break;
case" ; XHTMLStrict":
$ m_sDocType ="<!DOCTYPE html PUBLIC \" - // W3C // DTD XHTML 1.0 Strict // EN \" \http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ;;
休息;
case" XHTMLTransitional":
$ m_sDocType ="<!DOCTYPE html PUBLIC \" - // W3C // DTD XHTML 1.0 Transitional // EN \" \http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ;;
休息;
case" XHTMLFrameset":
休息;
}
}
// ************************ *********************
//名称:getHTMLString
//目的:输出HTML班级内容。
//参数:< none>
// ******************* ************************** *
公共函数getHTMLString()
{
返回$ m_sDocType;
}
}
// ******** *************************************
//名称:XHTML文件
//目的:代表一个xhtml文档对象
// ********************** ***********************
class XHTMLDocument
{
private $ m_oDocType;
private $ m_oHeadElement;
private $ m_oBodyElement;
private $ m_sProfile ="" ;;
private $ m_sDir ="" ;;
私人$ m_sLang ="" ;;
私人$ m_sXmlLang ="" ;;
// ********** ***************************************
//构造函数
// ******************************************** *
公共职能__construct($ profile,$ dir,$ lang,$ xmlLang)
{
$ m_sProfile = $ profile;
$ m_sDir = $ dir;
$ m_sLang = $ lang;
$ m_sXmlLang = $ xmlLang;
}
// ************************************* ********
// name:setDocumentType
//目的:设置要在本文档中使用的文档类型。
//参数:$ docType
// ******************************* **************
公共函数setDocumentType($ docType)
{
$ m_oDocType = $ docType;
}
// ************************* ********************
//名称:setHeadElement
//目的e:设置要在本文档中使用的head元素。
//参数:$ head
// ************ *********************************
公共函数setHeadElement($ head)
{
$ m_oHeadElement = $ head;
}
// ****** *****************************************
//姓名:setBodyElement
//目的:设置要在本文档中使用的body元素。
//参数:$ body
// *********************************************
公共函数setBodyElement($ body)
{
$ m_oBodyElement = $ body;
}
// ******************************************** *
// name:getHTMLString
//目的:输出类的HTML内容。
//参数:< none> ;
// *************************************** ******
公共函数getHTMLString()
{
$ htmlString ="" ;;
$ htmlString ="< html> \ n" ;;
$ htmlString。= $ m_oDocType-> getHTMLString(); //它会在这一行抛出错误。
$ htmlString。= $ m_oHeadElement-> getHTMLString();
$ htmlString。= $ m_oBodyElement-> getHTMLString( );
$ htmlString。="< / html> \ n" ;;
返回$ htmlString;
}
}
[/ PHP]
我在这一行收到错误:$ htmlString。= $ m_oDocType-> ; getHTMLString();
我知道这可能是非常简单的事情,但我只是没有看到它。任何帮助将不胜感激。
htmlDoc = new XHTMLDocument("","","","");
//添加DocType
DocType = new DocumentType(" XHTMLTransitional");
htmlDoc-> setDocumentType(
I am new to OO PHP and this is probably something really stupid, I have the following code in redirect.php:
[PHP]<?php
include("include_functions.php");
include("classes.xhtml.php");
include("classes.forms.php");
error_reporting(E_ALL);
ini_set(''display_errors'', True);
//set up XHTML Document Object
$htmlDoc = new XHTMLDocument("", "", "", "");
//Add DocType
$DocType = new DocumentType("XHTMLTransitional");
$htmlDoc->setDocumentType($DocType);
//Add Head Element
$headElement = new Head("","","","");
//Title Element
$titleElement = new Title("","","","","","","theDDHut paypal redirection");
$headElement->setTitleElement($titleElement);
//Add Script Element
$jScriptElement = new Script("text/javascript", "", "", "", "form_submission.js", "", "");
$headElement->addScriptElement($jScriptElement);
//body element
$bodyElement = new Body("","","","","","","","","","","","","","","", "","","","","","","","","","","","","");
//$bodyElement = new Body("","","","","","","","","","","","","","","", "","SubmitHiddenForm()","","","","","","","","","" ,"","");
//Add all of the pieces of the body the form is the only piece
if(isset($_POST))
{
$formElement = new Form(GetPayPalURL(),"POST","","","","","","","","" ,"","","","","","","");
foreach($_POST as $i => $value)
{
$inputField = new Input("","","","","","",$i,"","","","hidden",$valu e,"","","","","","","","");
$formElement->addElement($inputField);
}
$bodyElement->addElement($formElement);
}
$htmlDoc->setBodyElement($bodyElement);
echo($htmlDoc->getHTMLString());
?>[/PHP]
Then in classes.xhtml.php I have the following two relevant classes, but it is doing this for pretty much any class.
[PHP]
//*********************************************
// name: Documenttype
// purpose: represents a xhtml doctype object
//*********************************************
class DocumentType
{
private $m_sDocType = "";
//*********************************************
// initializer
//*********************************************
public function __construct($type)
{
switch ($type)
{
case "HTMLStrict":
$m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
break;
case "HTMLTransitional":
$m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
break;
case "HTMLFrameset":
$m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">";
break;
case "XHTMLStrict":
$m_sDocType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
break;
case "XHTMLTransitional":
$m_sDocType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
break;
case "XHTMLFrameset":
$m_sDocType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
break;
}
}
//*********************************************
// name: getHTMLString
// purpose: to output the HTML contents of the class.
// parameters: <none>
//*********************************************
public function getHTMLString()
{
return $m_sDocType;
}
}
//*********************************************
// name: XHTML Document
// purpose: represents a xhtml document object
//*********************************************
class XHTMLDocument
{
private $m_oDocType;
private $m_oHeadElement;
private $m_oBodyElement;
private $m_sProfile = "";
private $m_sDir = "";
private $m_sLang = "";
private $m_sXmlLang = "";
//*********************************************
// constructor
//*********************************************
public function __construct($profile, $dir, $lang, $xmlLang)
{
$m_sProfile = $profile;
$m_sDir = $dir;
$m_sLang = $lang;
$m_sXmlLang = $xmlLang;
}
//*********************************************
// name: setDocumentType
// purpose: to set the document type to be used in this document.
// parameters: $docType
//*********************************************
public function setDocumentType($docType)
{
$m_oDocType = $docType;
}
//*********************************************
// name: setHeadElement
// purpose: to set the head element to be used in this document.
// parameters: $head
//*********************************************
public function setHeadElement($head)
{
$m_oHeadElement = $head;
}
//*********************************************
// name: setBodyElement
// purpose: to set the body element to be used in this document.
// parameters: $body
//*********************************************
public function setBodyElement($body)
{
$m_oBodyElement = $body;
}
//*********************************************
// name: getHTMLString
// purpose: to output the HTML contents of the class.
// parameters: <none>
//*********************************************
public function getHTMLString()
{
$htmlString = "";
$htmlString = "<html>\n";
$htmlString .= $m_oDocType->getHTMLString(); //It throws the error on this line.
$htmlString .= $m_oHeadElement->getHTMLString();
$htmlString .= $m_oBodyElement->getHTMLString();
$htmlString .= "</html>\n";
return $htmlString;
}
}
[/PHP]
I get the error on this line: $htmlString .= $m_oDocType->getHTMLString();
I know this is probably something really simple, but I am just not seeing it. Any help would be greatly appreciated.
htmlDoc = new XHTMLDocument("", "", "", "");
//Add DocType
DocType = new DocumentType("XHTMLTransitional");
htmlDoc->setDocumentType(
这篇关于致命错误:在非对象上调用成员函数getHTMLString()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!