Skip to content

Instantly share code, notes, and snippets.

neloy-ahmed

Block or report user

Report or block neloy-ahmed

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@neloy-ahmed
neloy-ahmed / instanceof.php
Last active Jan 29, 2019
PHP interesting code
View instanceof.php
<?php
//Instanceof will return boolean if the object is an instance of a class
class Tome {
}
$k = new Tome();
View multiple_interface_inherit.php
<?php
interface World
{
public function draw_flag();
}
interface Animal
{
public function sounds();
}
View abstract_with_property.php
<?php
abstract class World{
//Abstract class can contain variable
public $var1 = 'hello ' . 'world';
//Abstract class can also contain constant
const b = 'i\'m a constant';
View interface_property.php
<?php
interface World{
public function draw_map($country_name);
public function draw_flag($country_name);
const b = 'Interface constant';
//Fatal error: Interfaces may not include member variables
public $var1 = 'hello ' . 'world';
View access_type_for_abstract_class_method.php
<?php
abstract class World{
abstract public function show_population($country_name);
abstract protected function draw_map($country_name);
//Fatal error: Abstract function World::draw_flag() cannot be declared private
abstract private function draw_flag($country_name);
public function show_info(){
View access_type_for_interface.php
<?php
interface World{
public function draw_map($country_name);
//Fatal error: Access type for interface method World::draw_flag() must be omitted
protected function draw_flag($country_name);
View interface_method_body_defined.php
<?php
interface World{
public function draw_map($country_name);
public function draw_flag($country_name);
//Fatal error: Interface function World::show_info() cannot contain body
public function show_info(){
print "This is an interface for World";
}
}
View interface.php
<?php
interface World{
public function draw_map($country_name);
public function draw_flag($country_name);
}
class Bangladesh implements World{
public function draw_map($country_name){
View abstract_class.php
<?php
abstract class World{
abstract protected function draw_map($country_name);
abstract protected function draw_flag($country_name);
public function show_info(){
print "This is an abstract class for World";
}
}
You can’t perform that action at this time.