On Tue, Oct 19, 2010 at 04:12:51PM -0400, David McGlone wrote:
> Hi everyone,
>
> I've been really good at googling to find my answers, but this time my
> method isn't working for me.
>
> I have created a very simple class and a constructor hoping to get a
> much better understanding of how to work with them. The code works, but
> because it's very simple, I'm not sure that the way I'm trying to
> access it is possible.
>
> All I'm trying to do is "access the class from outside the function".
> (is that how to describe it?)
>
> For instance I have this simple code:
>
> class simpleConstructer {
>
> function __construct() {
> echo "running the constructor";
> }
> }
>
> $test=new simpleConstructer();
>
You're trying to "instantiate the class". And the way you're doing it
here is correct. When you do this, $test becomes an object of this
class. If you had another function ("member") within the class called
"myfunction()", you could run it this way (after you instantiate the
class):
$test->myfunction();
>
> Basically I want to learn how I can (if it's possible with this simple
> code) is display the output on a different page.
>
> I tried putting the line: $test=new simpleConstructer(); on the index
> page and including the page the class is on, but it causes the index
> page to go blank.
You've likely got an error you're not seeing. Fix this first. If the
file your class is in is syntactically correct, and you do
include "simpleConstructerFile.php";
in your index.php file, it should flawlessly include the code. Then, in
your index.php, you do this:
$test = new simpleConstructer;
you should see the contents of the echo statement appear on the page.
So you're on the right track. You just need to find the error first.
>
> The thought of a session crossed my mind, but I'm pretty confident at my
> level to know I don't need a session.
You're right. Using a session would be completely unnecessary, and I'm
not even sure how it would assist at all.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php