note 115800 added to language.oop5.abstract
| From: | aloydev2586 at gmail dot com | Date: | Thu, 25 Sep 2014 09:33:14 +0000 |
| Subject: | note 115800 added to language.oop5.abstract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200524@lists.php.net to get a copy of this message | ||
Just in case you are confused about function arguments:
/*************Example 1********************/
abstract class my_class {
abstract public function my_function($number);
}
class subclass extends my_class {
public function my_function($new_number, $string = ' is an integer!!!')
{
echo $new_number . $string;
}
}
$var = new subclass();
$var->my_function(1024); //this will output: 1024 is an integer!!!
/*************Example 2********************/
abstract class my_class {
abstract public function my_function($number);
}
class subclass extends my_class {
//now $string = ' is a float!!!'
public function my_function($new_number, $string = ' is a float!!!')
{
echo $new_number . $string;
}
}
$var = new subclass();
//added ' is an integer'
$var->my_function(1024, ' is an integer!!!'); //this will output: 1024 is an
integer!!!, rewrote $string.
/*************Example 3********************/
abstract class my_class {
abstract public function my_function($number);
}
class subclass extends my_class {
//now $string isn't initialized
public function my_function($new_number, $string )
{
echo $new_number . $string;
}
}
$var = new subclass();
$var->my_function(1024, ' is an integer!!!'); /*this will trigger a fatal error of
incompatibility between subclass::my_function() and my_class::my_function($number)*/
/*************Example 4********************/
abstract class my_class {
abstract public function my_function($number);
}
class subclass extends my_class {
public function my_function($new_number, $string )
{
echo $new_number . $string;
}
}
$var = new subclass();
//no second argument, no matter
$var->my_function(1024);//fatal error too. Optional arguments have to be initialized in the
extending class function.
----
Server IP: 72.52.91.14
Probable Submitter: 201.226.182.16
----
Manual Page -- http://php.net/manual/en/language.oop5.abstract.php
Edit -- https://master.php.net/note/edit/115800
Del: integrated -- https://master.php.net/note/delete/115800/integrated
Del: useless -- https://master.php.net/note/delete/115800/useless
Del: bad code -- https://master.php.net/note/delete/115800/bad+code
Del: spam -- https://master.php.net/note/delete/115800/spam
Del: non-english -- https://master.php.net/note/delete/115800/non-english
Del: in docs -- https://master.php.net/note/delete/115800/in+docs
Del: other reasons-- https://master.php.net/note/delete/115800
Reject -- https://master.php.net/note/reject/115800
Search -- https://master.php.net/manage/user-notes.php