Re: OOP Newbie - why does this not work?
| From: | Jochem Maas | Date: | Fri, 21 Oct 2005 08:09:41 +0000 |
| Subject: | Re: OOP Newbie - why does this not work? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224388@lists.php.net to get a copy of this message | ||
Bob,
'wrapping' you class definition within HTML like you have done is
not only weird but down right ugly. I recommend sticking each class
you write in a seperate file and using include_once() or require_once()
before you output anything to the browser. basically try to
seperate you code into 'stages' (for want of a better word) e.g.:
1. setup an environment (includes loading classes)
2. process the request
3. redirect or output a page
Bob Hartung wrote:
Hi all,...
</head>
<body>
<br>
<P>This is outside the php code block</P>
<br>
<?php
echo "Start defining the class here: <BR>" ;
/* class Test
{
function __constructor()
{
var $saying ;
'var' doesn't belong here. it belongs directly in the body of class def.
$saying = "Im in the Test Class" ;
}
function get()
{
return $saying ;
there is a missing '}' here.
also you should be returning and setting $this->saying
}
var $liveclass ;
drop the 'var' - it's only for php4 and then only for
defining the properties of classes/objects:
class Test {
var $myProperty;
}
$liveclass = new Test ; echo $liveclass->get() ; echo "<BR>" ; echo "This is in the php code block" ;*/?></body> </html>