Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Encapsulation in PHP

<?php
   
class Student {
    private $firstname;
    private $gender;
   
    public function getFirstName() {
        return $this->firstname;
    }
   
    public function setFirstName($firstname) {
        $this->firstname = $firstname;
        echo("First name is set to ".$firstname);
        echo("<br>");
    }
   
    public function getGender() {
        return $this->gender;
    }
   
    public function setGender($gender) {
        if ('Male' !== $gender and 'Female' !== $gender) {
            echo('Set gender as Male or Female for gender');
        }
   
        $this->gender = $gender;
        echo("Gender is set to ".$gender);
        echo("<br>");
    }
}
   
$student = new Student();
$student->setFirstName('Meena');
$student->setGender('Female');
   
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php strftime year 2 digits 
Php :: laravel route model binding 
Php :: php unix socket client 
Php :: php add number to the existing name 
Php :: php array remove the last element 
Php :: workpress change page title from shortcode 
Php :: wordpress theme basics including CSS and js 
Php :: create qr code png image of 200*200 using phpqrcode 
Php :: query log laravel 
Php :: url rewrite htaccess php 
Php :: php artisan websockets serve 
Php :: laravel faker value or null 
Php :: laravel delete method 
Php :: PHP multidimensional array merge recursive 
Php :: send data with window.location.href 
Php :: get ids from object 
Php :: install multiple php versions windows 
Php :: laravel many to many relationship 
Php :: php replace url parameter value 
Php :: The last ship -inurl:(htm/html/php/pls/txt) intitle:index.of "last modified" (mp4/wma/aac/avi) 
Php :: what is php 
Php :: compare key and one array 
Php :: codeigniter sms send 
Php :: laravel project composer [ErrorException] Undefined index: name 
Php :: get data in php 
Php :: foreign key string laravel 
Php :: laravel collection all 
Php :: apache 2 
Php :: upload image in laravel 
Php :: Bd phone number validation in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =