ameliabob Posted February 4, 2016 Share Posted February 4, 2016 I am trying to create a class which will concatenate variables but it appears as though each time a function within a class is called the variables are reinitiated. Is there a way that the variables can be held so as to allow them to be added to? The first code box is the calling functions and the second is the class. <?php include ("myClasses.php"); $sTable = new TABLE(); $sTable->setHeading("This is the heading"); $sTable->setHeadingItem("Symbol"); $sTable->setHeadingItem("Name"); $sTable->setDetailItem("F"); $sTable->setDetailItem("Ford"); $sTable->endTable(); echo($sTable->showTable()); ?> myClasses.php <?php class TABLE { private $border; private $hdrStarted = false; private $rowStarted = false; private $numberOfRows=0; private $s; function __construct($border=null){ $s = "<table "; if(is_null($border)) $s .= ">"; else $s .= "border='".$border."'>"; } function setHeading($t){ $s .= "<caption>".$t."</caption>"; echo $s; } function setHeadingItem($t){ if(!$hdrStarted){ $s .= "<tr>"; $hdrStarted = true; } $s .= "<th>".$t."</th>"; } function setDetailItem($t){ if($hdrStarted){ $s .= "</tr>"; $hdrStarted = false; } if(!$rowStarted){ $rowStarted = true; $s .= "<tr>"; } $s .= "<td>".$t."</td>"; } function endTable(){ if($rowStarted || $hdrStarted) $s .= "</tr>"; $s .="</table>"; } function showTable(){ return $s; } } ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 4, 2016 Share Posted February 4, 2016 You need to use $this when you are referring to properties of your object. You should also make sure you have all error messages enabled: ini_set('display_errors', 1); error_reporting(E_ALL); http://php.net/manual/en/language.oop5.basic.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now