note 76190 added to keyword.extends
| From: | pierrorevrard at gmail dot com | Date: | Wed, 04 Jul 2007 12:13:39 +0000 |
| Subject: | note 76190 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128222@lists.php.net to get a copy of this message | ||
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?
----
Server IP: 195.26.5.11
Probable Submitter: 85.93.207.16
----
Manual Page -- http://www.php.net/manual/en/keyword.extends.php
Edit -- https://master.php.net/note/edit/76190
Del: integrated -- https://master.php.net/note/delete/76190/integrated
Del: useless -- https://master.php.net/note/delete/76190/useless
Del: bad code -- https://master.php.net/note/delete/76190/bad+code
Del: spam -- https://master.php.net/note/delete/76190/spam
Del: non-english -- https://master.php.net/note/delete/76190/non-english
Del: in docs -- https://master.php.net/note/delete/76190/in+docs
Del: other reasons-- https://master.php.net/note/delete/76190
Reject -- https://master.php.net/note/reject/76190
Search -- https://master.php.net/manage/user-notes.php