Skip to content

Commit 771d01d

Browse files
committed
Class 10 added
1 parent 024966c commit 771d01d

37 files changed

+170
-75
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
4+
interface Moveable {
5+
public function move();
6+
}
7+
8+
9+
interface Test {
10+
public function testMove();
11+
}
12+
13+
14+
class Man implements Moveable,Test {
15+
16+
public function move() {
17+
echo "A man can move<br/>";
18+
}
19+
20+
21+
public function testMove() {
22+
echo "Multiple Interface multiple inheritence<br/>";
23+
}
24+
25+
26+
}
27+
28+
29+
class Vehicle implements Moveable {
30+
31+
public function move() {
32+
echo "A Vehicle also can move";
33+
}
34+
35+
36+
}
37+
38+
39+
$mans = new Man();
40+
$mans->move();
41+
$mans->testMove();
42+
$machine = new Vehicle();
43+
$machine->move();
44+
?>
File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
class DB {
3+
4+
protected $table;
5+
6+
//Handle Absent Method
7+
public function __call($method, $args) {
8+
if (substr($method, 0, 5) == 'where') {
9+
$column = substr($method, 4);
10+
$column = $this->camelCaseToUnderscore($column);
11+
echo 'SELECT * FROM ' . $this->table . ' where ' . $column . '=' . $this->makeSqlString($args[0]);
12+
}
13+
}
14+
15+
// set table name
16+
public function table($name) {
17+
$this->table = $name;
18+
return $this;
19+
}
20+
21+
// make camelCase to snake_case
22+
protected function camelCaseToUnderscore($input) {
23+
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
24+
$ret = $matches[0];
25+
foreach ($ret as &$match) {
26+
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
27+
}
28+
return implode('_', $ret);
29+
}
30+
31+
// make sql string based on datatype
32+
protected function makeSqlString($val) {
33+
$types = ['integer', 'double', 'float'];
34+
35+
if (in_array(gettype($val), $types)) {
36+
return $val;
37+
}
38+
return "'{$val}'";
39+
}
40+
41+
}
42+
43+
$db = new DB;
44+
45+
$db->table('tbl_users')->whereFirstName('Nahid');
46+
47+
48+
?>
File renamed without changes.

Class-9-27-08-2020/Part#2/obj-clone.php renamed to Class-10-03-09-2020/Part#2/obj-clone.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
<?php
2+
23
class Corporate_Drone {
3-
private $employeeid;
4-
private $tiecolor;
5-
// Define a setter and getter for $employeeid
6-
function setEmployeeID($employeeid) {
4+
5+
private $employeeid;
6+
private $tiecolor;
7+
// Define a setter and getter for $employeeid
8+
function setEmployeeID($employeeid) {
79
$this->employeeid = $employeeid;
8-
}
9-
function getEmployeeID() {
10+
}
11+
12+
function getEmployeeID() {
13+
1014
return $this->employeeid;
11-
}
12-
// Define a setter and getter for $tiecolor
13-
function setTieColor($tiecolor) {
15+
}
16+
17+
// Define a setter and getter for $tiecolor
18+
function setTieColor($tiecolor) {
1419
$this->tiecolor = $tiecolor;
15-
}
16-
function getTieColor() {
20+
}
21+
22+
function getTieColor() {
1723
return $this->tiecolor;
18-
}
1924
}
25+
26+
}
2027
// Create new Corporate_Drone object
2128
$drone1 = new Corporate_Drone();
2229

0 commit comments

Comments
 (0)