0

I am in Ubuntu 11.10. When I write a simple script like echo phpinfo(); it runs and shows no error. But if I try to write some extra php code the browser server error page. What is the issue here I dont understand ??

Lets say if I change the code to the following it gives server error;

<?php
class MyClass{
    private $prop;
    public function __construct(){
        echo "The class \"".__CLASS__."\"was created";
    }
    public function __destruct(){
        echo "The class \"".__CLASS__."\" was destroyed";   
    }
    protected function getProperty(){
        return $prop;
    }
    public function __toString(){
        echo "__toString() method called.<br />";
        return $this->getProperty().'<br />';
    }
    public function setProperty($prop){
        $this->prop = $prop;
    }
}
class MyOtherClass extends MyClass{
    public function __construct(){
        parent::__contruct();
        echo "A new constructor in class \"".__CLASS__"\"";
    }
    public function newMethod(){
        echo 'From a new method in class '.__CLASS__.'<br />';
    }
}
$newClass = new MyOtherClass();
echo $newClass->getProperty();
?>
3
  • could you provide a code sample please? Commented Dec 7, 2011 at 0:11
  • What is the Sever Error? Commented Dec 7, 2011 at 0:14
  • HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. Commented Dec 7, 2011 at 0:19

1 Answer 1

3
class MyClass{
    protected getProperty(){
    //...

    public __toString(){
    //...

    public setProperty($prop){
    //...

class MyOtherClass extends MyClass{
    public __construct(){
    // ...

You're missing function after public/protected in several methods.


Couple more errors:

class MyOtherClass extends MyClass{
    public function __construct(){
        parent::__contruct();
        echo "A new constructor in class \"".__CLASS__"\"";
    }
    //...
  • You misspelled parent::_construct() without the s.
  • In your echo line, __CLASS__ is missing a . concatenation operator after it.

    echo $newClass->getProperty();

  • MyClass::getProperty() is protected, so you can't call it from out here.

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

9 Comments

Even if I had mistakes in code PHP interpreter should respond me with the errors. Anyways, I have edited the code above and the same error persists.
Sometimes PHP errors actually do cause 500 server errors, based on server setup. What's in the error log?
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request
@insane-36 I meant the PHP error log. Also check php.ini to make sure logging is enabled first.
@insane-36 Perhaps this will help? HTTP Error 500 Internal server for php pages
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.