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.
27 2815
I don't know what happened to the reply that I responded to but Purple said to remove the m_ out of the variable names.
Thanks so much for the help, but unfortunately it didn't work, I still got the same error. I turned on debugging and it gave me a little more information: Notice: Undefined variable: oDocType
So I am guessing I am doing something wrong in the setDocumentType function of the XHTML object.
Another question related to your suggestion, does PHP not like _ in variable names?
Thanks
Hi - Sorry about that - I replied and then checked again and realised I had missed the declarations at the start of the class
Still looking at it tho :)
Hi,
PHP is more than happy with underscore in variable names..
Purple
Hi,
PHP is more than happy with underscore in variable names..
Purple
Thanks, I know it is kind of old fashioned but I like hungarian notation. :-)
Hi,
[PHP]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]
The error is telling you PHP can't resolve the function you are trying to call - I am having difficulty understanding what you are expecfing the call to $m_oDocType->getHTMLString() to generate. $m_oDocType appears to hold a string value when it should be a reference to an object generated using NEW or $this (meaning this class..)
Not sure if this helps any - if you can post the missing classes I am interested enough now to run it on my system and fix it..
Purple
I will post each file in a separate post, but first, I am trying to make each of the xhtml elements an object so that I can build the objects and then iterate through them and call a generic getHTMLString function on them to get the xhtml contained within it.
this will really come in handy for the head, body, div, form, etc... tags that are containers for other tags.
thanks.
Also
[PHP]$htmlString = "";
$htmlString = "<html>\n";[/PHP]
the first $htmlString is redundant, when setting variables $a = 'b' the variable $a is cleared and == 'b' and only 'b' :)
if it was a typo accept my apologies..
Purple
include_functions.php
[PHP]
<?php
//*********************************************
// © 2007 Two Miles Solutions, LLC
//
// name: include_functions.php
// programmer: jmiles
// purpose: include functions for the dd hut website
// modifications: created 05/11/2007
//*********************************************
//*********************************************
// name: GetPayPalURL
// purpose: returns the PayPal URL to redirect to
// parameters: <none>
//
// output: the URL for PayPal
//*********************************************
function GetPayPalURL()
{
$paypalURL = "https://www.paypal.com/cgi-bin/webscr"; //put the paypal address here.
return $paypalURL;
}
?>
[/PHP]
it says that the code is too long, can you pm me with your email address and I will send you the files?
Hi
did you try :
[PHP]$doctype->getHTMLString();[/PHP]
I am not clear on where you at with scope so throw in a
[PHP]global $doctype; [/PHP]
just before it to see if it runs..
Purple
Hi
did you try :
[PHP]$doctype->getHTMLString();[/PHP]
I am not clear on where you at with scope so throw in a
[PHP]global $doctype; [/PHP]
just before it to see if it runs..
Purple
I tried just throwing this in right after I set the document type on the xhtml object
[PHP]$doctype->getHTMLString();[/PHP]
and I got this notice: Notice: Undefined variable: m_sDocType
so I think you are right that it is a scope issue, but I don't know how to fix it.
Hi,
I think
[PHP] public function getHTMLString()
{
return $m_sDocType;
}[/PHP]
should be
[PHP]public function getHTMLString()
{
return $this->m_sDocType;
}[/PHP]
Hi,
I think
[PHP] public function getHTMLString()
{
return $m_sDocType;
}[/PHP]
should be
[PHP]public function getHTMLString()
{
return $this->m_sDocType;
}[/PHP]
I think you are right, I will give it a try, but it is going to take me a while...I'm actually sitting in a training class :-)
I think you are right, I will give it a try, but it is going to take me a while...I'm actually sitting in a training class :-)
I hope its something interesting :)
I did pm you my hotmail email address - if you want to mail me the code zipped, I can take a look and post my findings back on this thread
I think class DocumentType should be somewhat more like this..
[PHP]class DocumentType
{
private $m_sDocType = "";
//*********************************************
// initializer
//*********************************************
public function __construct($type)
{
switch ($type)
{
case "HTMLStrict":
$this->m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
break;
case "HTMLTransitional":
$this->m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
break;
case "HTMLFrameset":
$this->m_sDocType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">";
break;
case "XHTMLStrict":
$this->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":
$this->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":
$this->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 $this->m_sDocType;
}
}[/PHP]
and XHTML Document like
[PHP]//*********************************************
// 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)
{
$this->m_sProfile = $profile;
$this->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 have made the changes, now it is crapping out on me here:
[PHP]
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)
{
$this->$m_sProfile = $profile;
$this->$m_sDir = $dir;
$this->$m_sLang = $lang;
$this->$m_sXmlLang = $xmlLang;
}
[/PHP]
it is blowing up on this line
[PHP]$this->$m_sProfile = $profile;[/PHP]
it gives me this set of notifications and warnings: Notice: Undefined variable: m_sProfile in <path> on line 77 Fatal error: Cannot access empty property in <path> on line 77
How does it not know where the variable is? I have declared it right above it.
thanks for all of your help.
FYI - one other thing I needed to do was change
[PHP]$array[] = $var[/PHP]
to
[PHP]array_push($array, $var);[/PHP]
Ignore the last post - I ran out of time after mis editing it :)
Try this for class XHTMLDocument..
[PHP]//*********************************************
// 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)
{
$this->m_sProfile = $profile;
$this->m_sDir = $dir;
$this->m_sLang = $lang;
$this->m_sXmlLang = $xmlLang;
}
//*********************************************
// name: setDocumentType
// purpose: to set the document type to be used in this document.
// parameters: $docType
//*********************************************
public function setDocumentType($docType)
{
$this->m_oDocType = $docType;
}
//*********************************************
// name: setHeadElement
// purpose: to set the head element to be used in this document.
// parameters: $head
//*********************************************
public function setHeadElement($head)
{
$this->m_oHeadElement = $head;
}
//*********************************************
// name: setBodyElement
// purpose: to set the body element to be used in this document.
// parameters: $body
//*********************************************
public function setBodyElement($body)
{
$this->m_oBodyElement = $body;
}
//*********************************************
// name: getHTMLString
// purpose: to output the HTML contents of the class.
// parameters: <none>
//*********************************************
public function getHTMLString()
{
global $DocType;
$htmlString = "";
$htmlString = "<html>\n";
$htmlString .= $DocType->getHTMLString(); //It throws the error on this line.
$htmlString .= $this->m_oHeadElement->getHTMLString();
$htmlString .= $this->m_oBodyElement->getHTMLString();
$htmlString .= "</html>\n";
return $htmlString;
}
} [/PHP]
Let me know - when you get out of your training class..
Regards Purple
I posted one right before your long post, did you see it? With the exception of the global declaration our code is the same now. It doesn't seem to like the $this-> reference in front of string variables.
thanks for all of your help.
I posted one right before your long post, did you see it? With the exception of the global declaration our code is the same now. It doesn't seem to like the $this-> reference in front of string variables.
thanks for all of your help.
I am happy to help - would be easier if you could send me the code.. :)
Hi,
I am back online - my broadband service died and has just returned - I have received the scripts and will take a look now..
Purple
thanks, I really appreciate the help. I am almost done with training but will need to get working on this soon.
Hi,
there is rather a lot of code..
Going back to an earlier post and to provide some feedback - the change to utilising the $this-> approach to access variables defined within the class is
$this->variable_name
not
$this->$variable_name
Let me keep looking ;-)
Purple
i think i have worked a lot of the major kinks out now, thanks for all of the help, you're awesome.
Hey - Pleased you have found your way through it..
I was worried I was fixing your college assignment until I found your website. :)
Rgds
Hey - Pleased you have found your way through it..
I was worried I was fixing your college assignment until I found your website. :)
Rgds
Nope, not a college assignment, just trying to create some base classes that I can use when developing websites that make my life easier. Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Daniel Hansen |
last post by:
I am getting a "Fatal error: Call to undefined function:
imagecreatefromjpeg() in..." error in one of my scripts, and after doing
a bit of searching on the 'net I found various messages relating to...
|
by: PeterF |
last post by:
Hello,
what is wrong here? the purpose is to create an array of objects and then
interate over it,
calling some method from all of them.
I get just the following at the marked line ("// FATAL...
|
by: gc |
last post by:
I'm a PHP and MySQL newbie. I have a feeling a lot of you may have seen this
before. I'm teaching myself PHP/MySQL and trying to setup a guestbook. I'm
running latest versions of Apache, PHP and...
|
by: Tim Tyler |
last post by:
I'm getting fatal errors when executing code - and my error handler is
failing to trap them - so I get no stack backtrace :-(
The error I am getting is:
"Fatal error: Call to a member function...
|
by: dmitry.freitor |
last post by:
Why would someone call a non-static provate member function from
another non-static member function of the same class via the this
pointer?
Thanks.
DF
|
by: Ook |
last post by:
What am I doing wrong? This code gives a compile error:
'SortedList<T>::insert' : illegal call of non-static member function. I've
tried several variations of this, but keep getting the same error....
|
by: Jesper Stocholm |
last post by:
I have a recursive function that I would like to do a lot of recursive
calls (preferebly 2^20 in total)
The function is called as (with maxi = e.g. 100000)
DoRecursion(0,maxi,bseed,sha);
...
|
by: Fred W |
last post by:
I have 2 dependent dropdowns and would like to populate the contents
of the child dropdown dynamically based on the selected item of the
parent.
Pretty standard requirement.
However, can this...
|
by: mast2as |
last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the
code to thow exceptions. Whenever an exception is thrown the
TExceptionHander constructor takes an error code (int) as an...
|
by: Ian825 |
last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |