Tuesday, 9 June 2020

how to generate custome error message $age = 18; try { if try failed, go to else, it has throw , it will call catch, at that it wil execute throw whenever else comes comes to thtrow } and execute in catch catch() { } = 18){ echo ' you can vote'; if it is not age is equalto 18 } else { throw the error as exception with text throw new Exception ('YOU CANT ENTER'); whats we given text } that will catched by catch with catch (Exception $ex){ echo $ex -> getmessage(); automatically get by the message function and loads to ex and prints } ?>

we can use example variables from extend, but we cant use an example with example not reverse possible
<?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;
echo $ae -> displaystring();
$ex = new Example;
echo $ex ->displaystring();

?>
oop.php
<?php
class BankAccount {


public $balance = 0;


public function displayBalance(){
return 'Balance : '.$this-> balance. '</br> </br>' ;
}
public function deposit($amount){
$this -> balance = $this -> balance + $amount;
}
public function withdraw($amount){
if (($this -> balance)< $amount){
echo 'u cant withdraw more than ur balance';
}
else{$this -> balance = $this -> balance - $amount;}
}}



?>




oop59_2.php
<?php


require 'oop.php';
we can use other page variables using require
class SavingsAccount extends BankAccount {
using extend we can use othr class

}


class CurrentAccount extends BankAccount {

}

$viki_ca = new CurrentAccount;
$viki_ca -> deposit(1000);
$viki_ca -> withdraw(30000);
echo '</br>current account balance '.$viki_ca -> displayBalance();


$viki_sa = new SavingsAccount;
$viki_sa -> deposit(1000);
$viki_sa -> withdraw(500);
echo  '</br>savings  account balance '. $viki_sa -> displayBalance();



?>

how to use other class
how can I declarea objects and properties and how tostore information
hpow to use other page variables to run the obejcts
how to use other cother page variables
how can I use 
how to use other class variable without writing whole  code
class
publuc
public function
echo
class extends
public 
public function
return
new
display
new 
display
class
public
public function
return
public funciton
public funciton
if else
require
class extends
class extends
new
new
echo



No comments:

Post a Comment