Newsgroup: it.comp.www.php
Titolo: PHP 5.0

ho letto cose fantastiche su php 5.0 con zend engine 2.0
come una vera gestione degli oggetti!!
Sapete per quando č prevista la nuova versione?

 come una vera gestione degli oggetti!!
Io sono molto piú interessato a try/catch che ad un OOP piú sofisticato...
Massimo


Vuoi dire che con la 5.0 sarà possibile la gestione delle
eccezioni oppure è un tuo desiderio?:)
-- 
WEbdOM webmaster di
Metronic.It mobile phone philosophy
www.gadgetpoint.it
 serigrafia on line

ECCO QUELLO CHE PUOI FARE CON PHP 5.0 E IL MOTORE DI ZEND 2.0
Udite udite:
ma non mi sporcate lo schermo di bava....    ; )
Example 1: A singleton (static members)
=======================================
<?php
    class Counter {
        var $counter = 0;
        function increment_and_print()
        {
                print ++$this->counter;
                print "n";
        }
    }
    class SingletonCounter {
        static $m_instance = NULL;
        function Instance()
        {
                if (self::$m_instance == NULL) {
                    self::$m_instance = new Counter();
                }
                return self::$m_instance;
        }
    }
    SingletonCounter::Instance()->increment_and_print();
    SingletonCounter::Instance()->increment_and_print();
    SingletonCounter::Instance()->increment_and_print();
?>
Example 2: Factory method (derefencing objects returned from functions)
=======================================================================
<?php
    class Circle {
        function draw()
        {
            print "Circlen";
        }
    }
    class Square {
        function draw()
        {
            print "Squaren";
        }
    }
    function ShapeFactoryMethod($shape)
    {
        switch ($shape) {
            case "Circle":
                return new Circle();
            case "Square":
                return new Square();
        }
    }
    ShapeFactoryMethod("Circle")->draw();
    ShapeFactoryMethod("Square")->draw();
?>
Example 3: Nested class
=======================
<?php
    class Database {
        class MySQL {
            var $host = "";
            function db_connect($user) {
                print "Connecting to MySQL database '$this->host' as
$usern";
            }
        }
        class Oracle {
            var $host = "localhost";
            function db_connect($user) {
                print "Connecting to Oracle database '$this->host' as
$usern";
            }
        }
    }
    $MySQL_obj = new Database::MySQL();
    $MySQL_obj->db_connect("John");
    $Oracle_obj = new Database::Oracle();
    $Oracle_obj->db_connect("Mark");
    unset($MySQL_obj);
    unset($Oracle_obj);
?>
Example 3: Nested class suitable for a PEAR like hierarchy
==========================================================
<?php
    class DB::MySQL {
        var $host = "";
        function db_connect($user) {
            print "Connecting to MySQL database '$this->host' as $usern";
        }
    }
    class DB::Oracle {
        var $host = "localhost";
        function db_connect($user) {
            print "Connecting to Oracle database '$this->host' as $usern";
        }
    }
    $MySQL_obj = new DB::MySQL();
    $MySQL_obj->db_connect("Susan");
    $Oracle_obj = new DB::Oracle();
    $Oracle_obj->db_connect("Barbara");
?>
Example 4: Class constants and class scope
==========================================
<?php
    class ErrorCodes {
        const FATAL = "Fatal errorn";
        const WARNING = "Warningn";
        const INFO = "Informational messagen";
        function print_fatal_error_codes()
        {
            print "FATAL = " . FATAL;
            print "self::FATAL = " . self::FATAL;
        }
    }
    /* Call the static function and move into the ErrorCodes scope */
    ErrorCodes::print_fatal_error_codes();
?>
Example 5: Regular object method using both local and global functions
======================================================================
<?php
    class HelloWorld {
        const HELLO_WORLD = "Hello, World!n";
        function get_hello_world()
        {
            return HELLO_WORLD;
        }
        function length_of_hello_world()
        {
            $str = get_hello_world();
            return strlen($str);
        }
    }
    $obj = new HelloWorld();
    print "length_of_hello_world() = " . $obj->length_of_hello_world();
    print "n";
?>
Example 6: Multiple derefencing of objects returned from methods
================================================================
<?php
    class Name {
        function Name($_name)
        {
            $this->name = $_name;
        }
        function display()
        {
            print $this->name;
            print "n";
        }
    }
    class Person {
        function Person($_name, $_address)
        {
            $this->name = new Name($_name);
        }
        function getName()
        {
            return $this->name;
        }
    }
    $person = new Person("John", "New York");
    print $person->getName()->display();
?>
Example 7: Exception handling
=============================
<?
    class MyException {
        function MyException($_error) {
            $this->error = $_error;
        }
        function getException()
        {
            return $this->error;
        }
    }
    function ThrowException()
    {
        throw new MyException("'This is an exception!'");
    }
    try {
    } catch ($exception) {
        print "There was an exception: " . $exception->getException();
        print "n";
    }
    try {
        ThrowException();
    } catch ($exception) {
        print "There was an exception: " . $exception->getException();
        print "n";
    }
?>
Example 8: __clone()
===================
<?
    class MyCloneable {
        static $id = 0;
        function MyCloneable()
        {
            $this->id = self::$id++;
        }
        function __clone()
        {
            $this->name = $clone->name;
            $this->address = "New York";
            $this->id = self::$id++;
        }
    }
    $obj = new MyCloneable();
    $obj->name = "Hello";
    $obj->address = "Tel-Aviv";
    print $obj->id;
    print "n";
    $obj = $obj->__clone();
    print $obj->id;
    print "n";
    print $obj->name;
    print "n";
    print $obj->address;
    print "n";
?>
Example 9: Unified constructors
===============================
<?
    class BaseClass {
        function __construct()
        {
            print "In BaseClass constructorn";
        }
    }
    class SubClass extends BaseClass {
        function __construct()
        {
                parent::__construct();
                print "In SubClass constructorn";
        }
    }
    $obj = new BaseClass();
    $obj = new SubClass();
?>
Example 10: Destructors
=======================
<?php
class MyDestructableClass {
    function __construct()
    {
        print "In constructorn";
        $this->name = "MyDestructableClass";
    }
    function __destruct()
    {
        print "Destroying " . $this->name . "n";
    }
}
$obj = new MyDestructableClass();
?>

 eccezioni oppure è un tuo desiderio?:)
http://www.zend.com/engine2/ZendEngine-2.0.pdf
http://www.zend.com/zend/zend-engine-summary.php
Massimo


http://www.zend.com/zend/zend-engine-summary.php
Urka!
E io che volevo mettermi seriamente sotto con J2EE:))
Eppure su 
zend.com
 c'ero stato e non sono riuscito a trovare
nulla prima:p


Interessante, interessante...
come detto in un altro post, l'unico modo prima per avere una struttura del
genere erano le servlet!
E' interessante anche l'utilizzo di nomi unici per costruttori e distruttori -
ma per quanto riguarda l'ereditarieta'...??
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Mattia "The Killer" Belletti --- Student in Computer Science @ unibo
 Mail address: 
mbel...@cs.unibo.it
 --- Spam not allowed!!! :)
 ICQ: 33292311 --- IRC nickname: BluShine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

l'ereditarietà è più o meno discutibile
forse permetteranno
l'eredit multipla

 ECCO QUELLO CHE PUOI FARE CON PHP 5.0 E IL MOTORE DI ZEND 2.0
Contenti voi... io non ci capisco niente ^__^
-- 
PiKey
"Grazie a Dio, sono ateo!"
(©2001 Wago)