note 76190 deleted from keyword.extends by bjori
| From: | bjori@php.net | Date: | Tue, 24 Jul 2007 11:20:01 +0000 |
| Subject: | note 76190 deleted from keyword.extends by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128878@lists.php.net to get a copy of this message | ||
Note Submitter: pierrorevrard at gmail dot com
----
Did you know that ?
Because PHP4 don't apply visibility of properties and methods, in a parent class, you can call
a method of a children class ( if this method exists )!!! Same thing with properties, in a parent
class, you can use a child property!
See example below:
<?php
error_reporting( 2047 );
//parent class
class my_name
{
function my_name( $name )
{
//_name comes from child class
$this -> _name = $name;
}
function set( $name )
{
//_check comes from child class
if( $this -> _check( $name ) )
{
$this -> _name = $name;
}
}
}
//child class
class my_infos extends my_name
{
var $_name;
function my_infos( $name )
{
$this -> my_name( $name );
}
function _check( $name )
{
$name = trim( $name );
return ( ! empty($name) );
}
function get()
{
return $this -> _name;
}
}
$infos = new my_infos( 'Me' );
//set comes from my_name class
$infos -> set( 'Another' );
echo '<pre>' . $infos -> get() . '</pre>';
//no errors, show: Another
?>
I don't think that it's allowed in real Oriented 0bject Programming ( in PHP5 or C++ by
example ) but it works on PHP4.
This may be useful, not?