简体   繁体   中英

PHP server error in ubuntu 11.10

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();
?>
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM