php contruct parent
<?php class BaseClass { function __construct() { print "In BaseClass constructor\n"; } } class SubClass extends BaseClass { function __construct() { parent::__construct(); print "In SubClass constructor\n"; } } class OtherSubClass extends BaseClass { // inherits BaseClass's constructor } // In BaseClass constructor $obj = new BaseClass(); // In BaseClass constructor // In SubClass constructor $obj = new SubClass(); // In BaseClass constructor $obj = new OtherSubClass(); ?>
Source: www.php.net
construct php
class Example1 { public $cache_file; function __construct() { // some PHP code... } function __destruct() { $file = "/var/www/cache/tmp/{$this->cache_file}"; if (file_exists($file)) @unlink($file); } } // some PHP code... $user_data = unserialize($_GET['data']); // some PHP code...
Source: owasp.org
constructor in php
<?php class Car { public $name; public $color; function __construct($name) { $this->name = $name; } function get_name() { return $this->name; } function get_color() { return $this->color; } } $mycar = new Car("Audi"); $mycar->color = "red"; echo $mycar->get_name(); // Audi echo $mycar->get_color(); // red