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();
?>
Sandeep
  • 20,908
  • 7
  • 66
  • 106

1 Answers1

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.

Wiseguy
  • 20,522
  • 8
  • 65
  • 81
  • 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. – Sandeep Dec 07 '11 at 00:20
  • Sometimes PHP errors actually do cause 500 server errors, based on server setup. What's in the error log? – Wiseguy Dec 07 '11 at 00:22
  • HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request – Sandeep Dec 07 '11 at 00:27
  • @insane-36 I meant the PHP error log. Also check php.ini to make sure logging is enabled first. – Wiseguy Dec 07 '11 at 00:28
  • @insane-36 Perhaps this will help? [HTTP Error 500 Internal server for php pages](http://www.cyberciti.biz/tips/http-error-500-internal-server-for-php-pages-and-solution.html) – Wiseguy Dec 07 '11 at 00:34
  • I am not sure where to look inside php.ini. – Sandeep Dec 07 '11 at 00:34
  • @insane-36 Here are relevant configuration options: http://www.php.net/manual/en/errorfunc.configuration.php – Wiseguy Dec 07 '11 at 00:36
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5638/discussion-between-insane-36-and-wiseguy) – Sandeep Dec 07 '11 at 00:42
  • @insane-36 Does it work after you fix the additional errors I mentioned? Also see this question: [PHP - 500 instead of error](http://stackoverflow.com/questions/7301573/php-500-instead-of-error). – Wiseguy Dec 07 '11 at 00:44