__Construct在OOP类中? [关闭]

I am newish to the OOP style of PHP5, I have noticed __construct and __deconstruct within example classes and production classes.

I have read over the manual of this:

http://php.net/manual/en/language.oop5.decon.php

and looked over a range of questions/answers on StackOverflow. I'm still having trouble to understand what is the actual meaning of its exisitance?

class foo {
   function __construct()
   {
     // do something 
   }

   public function Example ()
   {
    echo "Example Functions";
   }

   function __destruct()
   {
     // do something
   }
}

The same class can function the same with no hits as:

class foo {
       public function Example ()
       {
        echo "Example Functions";
       }
    }

But the manual states with the above example, that my first function will take over the role as the __construct

Why is this a priority within PHP5 OOP Classes?

class Foo {
    public function __construct() {
        print("This is called when a new object is created");
        // Good to use when you need to set initial values,
        // (possibly) create a connection to a database or such.
    }

    public function __destruct() {
        print("This is called when the class is removed from memory.");
        // Should be used to clean up after yourself, close connections and such.
    }
}

$foo = new Foo();

Addition,

class Person {

    private $name; // Instance variable
    private $status; // Instance variable

    // This will be called when a new instance of this class i created (constructed)
    public function __construct($name, $age) {
        $this->name = ucfirst($name); // Change input to first letter uppercase.

        // Let the user of our class input something he is familiar with,
        // then let the constructor take care of that data in order to fit
        // our specific needs.
        if ($age < 20) {
            $this->status = 'Young';
        } else {
            $this->status = 'Old';
        }
    }

    public function printName() {
        print($this->name);
    }

    public function printStatus() {
        print($this->status);
    }
}

$Alice = new Person('alice', 27);
$Alice->printName();
$Alice->printStatus();

/Addition

If you run the above code and read the comments you should be able to understand when and how constructors and destructors should be used.

__deconstruct

A destructor is invoked when a class is about to be garbage collected, it allows you to perform last minute operations, before the class is disposed.

A _contructor is just the opposition. It allows you to set properties to your object during its creation.

This was the old way of creating a constructor, which according to the documentation was left there for backward compatibility.

public function Example ()
{
  echo "Example Functions";
}

"For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics."

http://php.net/manual/en/language.oop5.decon.php

You need to realize that a class defines a type, meaning both a kind of data and the operations that can be performed on that data. That data is stored internally as member variables. Similarly, those operations are defined by a class' methods. A constructor is used to initialize an object's initial internal state (that is, its member variables and any internal operations).

Destructors in PHP are generally used for manual object cleanup. They're not used all that often due to PHP's fire-and-forget nature. They might be used to free up resources (db connections, file handles) in long running scripts.