1

Hi all I have a quick question about the construction of objects in PHP. I'm currently using the Zend framework to make a small test application to familiarize myself with the Zend way of doing things. However I have come across an error that is unfamiliar to me. In my controller I create the object $student like so:

$student = new Application_Model_Student();

However doing this causes my page to dump a 500 error and no debugging output. My constructor for this model doesn't actually do anything but print "Hello Creation" out. Here's my code for the model:

<?php

class Application_Model_Student
{

    protected $_lastName;
    protected $_firstName;
    protected $_email;
    protected $_concentration;
    protected $_yearEntered;

    public function __construct()
    {
          print "Hello Creation";
    }

}
?>

Is there something wrong with my constructor? Or something in the way that I call it?

Chris Maness
  • 1,682
  • 3
  • 22
  • 40
  • Can't answer this without seeing the error. [Read the first question in the PHP FAQ](http://stackoverflow.com/tags/php/info) or [this question](http://stackoverflow.com/questions/1824282/php-production-server-turn-on-error-messages) to figure out how to enable error reporting. – Mike B Mar 15 '12 at 16:53
  • Thanks so much. Sorry for wasting your time. – Chris Maness Mar 15 '12 at 17:00

2 Answers2

1

The only thing I can think of is that the autolader can't find your class and is throwing an exception; resulting in the 500 error.

Two ways to check this:

  1. Manually include your file
  2. Wrap the instantiation in a try{}catch{} to see if it is the autoloader

(actually there's many more ways to check but these are a quick two).

Also don't bother closing the ?> in your class file, can often have whitespace after it causing you header issues in the longer term.

Lloyd Watkin
  • 485
  • 4
  • 10
0

Ensure that you have set you APPLICATION_ENV to 'development' so that you can see the error message.

If you still get a white screen, then there's a syntax error in code before this file. turn on error_reporting and error_logging in your php.ini file and look in the error log file created.

Rob Allen
  • 12,643
  • 1
  • 40
  • 49