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?

2
  • Can't answer this without seeing the error. Read the first question in the PHP FAQ or this question to figure out how to enable error reporting. Commented Mar 15, 2012 at 16:53
  • Thanks so much. Sorry for wasting your time. Commented Mar 15, 2012 at 17:00

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.