oop
|
|||||||||||||||||||||||
how to print text which is stored in object
|
|||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||
class Example{
|
declared class, declared property and write function to display,
|
||||||||||||||||||||||
public $text = 'welcome to telug computer worlds';
|
|||||||||||||||||||||||
public function display (){
|
|||||||||||||||||||||||
echo '<h2>' .$this -> text. '</h2>';
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
$ex = new Example;
|
declared object
|
||||||||||||||||||||||
echo $ex -> text;
|
load that text to ex and print
|
||||||||||||||||||||||
echo $ex -> display();
|
load that display output to ex and print that
|
||||||||||||||||||||||
?>
|
|||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||
class Example{
|
|||||||||||||||||||||||
public $text = 'welcome to telug computer worlds';
|
|||||||||||||||||||||||
public function display (){
|
|||||||||||||||||||||||
echo '<h2>' .$this -> text. '</h2>';
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
class AnExample extends Example{
|
without writng whole code from previous class, simply write
extend, using this we can use the
variables
|
||||||||||||||||||||||
}
|
|||||||||||||||||||||||
$ae = new AnExample;
|
|||||||||||||||||||||||
echo $ae -> text;
|
|||||||||||||||||||||||
echo $ae -> display();
|
|||||||||||||||||||||||
?>
|
|||||||||||||||||||||||
how to print text which is stored in object
|
|||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||
class Example{
|
|||||||||||||||||||||||
public $text = 'welcome to telug computer worlds';
|
|||||||||||||||||||||||
public function display (){
|
|||||||||||||||||||||||
echo '<h2>' .$this -> text. '</h2>';
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
$ex = new Example;
|
|||||||||||||||||||||||
echo $ex -> text;
|
|||||||||||||||||||||||
echo $ex -> display();
|
|||||||||||||||||||||||
?>
|
|||||||||||||||||||||||
how to use other class
|
|||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||
class Example{
|
|||||||||||||||||||||||
public $text = 'welcome to telug computer worlds';
|
|||||||||||||||||||||||
public function display (){
|
|||||||||||||||||||||||
echo '<h2>' .$this -> text. '</h2>';
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
class AnExample extends Example{
|
|||||||||||||||||||||||
public $string = 'telugu computer world';
|
|||||||||||||||||||||||
public function displayString (){
|
|||||||||||||||||||||||
return '<h1> .$this -> string .'</h1>';
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
}
|
|||||||||||||||||||||||
$ae = new AnExample;
|
|||||||||||||||||||||||
$ae -> displaystring();
|
|||||||||||||||||||||||
?>
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Tuesday, 9 June 2020
how to print text which is stored in object
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment