Thanks folks that is some help.
I am used to Delphi OOP for some 10years. there all variables in a class are grouped. those under a heading 'private' are private thiose under the group protected are and those under the public are public. Everything in a class is assumed a member of the class and then there is no need for all the 'this' business.
Fred.hat is a hat of the fred class.
However my book says that 'var' although deprecated = public (as from earlier php) and that I must use 'tostring' to output strings...which I find strange.
Of course Delphi is closely typed so a variable is declared at the outset as a string and always remains so. So does not need a cast.
Here if you are interested is the code for class 'tempbook' which is a temporary booking. (in my work all classes start with capital T
Code: Select all
class Ttempbook
{
var $tempbooknum=0;
var $daterow;
var $userlist = array();
var $userindex = 0;
var $length = 0;
var $ahead = 0;
var $letter= 'z';
var $email = '';
var $startdate='abc ';
var $enddate=' ';
var $startday='';
var $endday = '';
function __construct($tempbooknum,$daterow)
{
$this->tempbooknum = $tempbooknum;
$this->daterow = $daterow;
$this->startdate = $daterow['startdate'];
$this->enddate = $daterow['enddate'];
$this->email = $daterow['email1'];
$startbits = explode('/',$this->startdate); // dd/mm/yyyy
$endbits = explode('/',$this->enddate);
$starttime = mktime(0,0,0,$startbits[1],$startbits[0],$startbits[2]);
$this->startday = date("D",$starttime); //day of week
$endtime = mktime(0,0,0,$endbits[1],$endbits[0],$endbits[2]);
$this->endday = date("D",$endtime);
$uksdate = $startday." ".$startdate;
$ukedate = $endday." ".$enddate;
$aday = (60 * 60 * 24);
$this->length =($endtime-$starttime )/$aday +1;
$today = time();
$this->ahead = (mktime(0,0,0,$startbits[1],$startbits[0],$startbits[2]) - $today)/$aday;
$db = & JFactory::getDBO();
$qry =
"select " .$db->nameQuote('periodletter').
"," .$db->nameQuote('periodend').
"from " .$db->nameQuote('#__1_periods').
";";
$db->setQuery($qry);
$letters=$db->loadResultArray(0);
$days = $db->loadResultArray(1);
$len=$this->length;
// echo "<p>days = "; print_r($days); echo"</p>";
for($jj=0;$jj<5;$jj++){
if ($days[$jj] > $len)
break;
}
$this->letter=$letters[$jj];
} // end of construct
function addUser($username)
{
$this->userlist[]=$username;
}
}// end of class so far
Then in another script I put at some point
Code: Select all
$thebooking = new Ttempbook($tempbooknum,$daterow);
.
.
echo "<p>$thebooking->$email</p>";
//and various other echo ...<p>$thebooking->variables</p> with the output format controlled by css
That gives an error message
I tried to force the types by initialising with a string but PHP won't have that.
So thanks I will try your solution but I am still confused about 'tostring' except as applied to a class as a whole rather than its member variables
--
Dave