File tree Expand file tree Collapse file tree 17 files changed +541
-0
lines changed Expand file tree Collapse file tree 17 files changed +541
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class Man
4
+ {
5
+ function hand ($ substance )
6
+ {
7
+ return 'I grab the ' . $ substance ;
8
+ }
9
+
10
+ function leg ($ path )
11
+ {
12
+ return 'I go to ' . $ path ;
13
+ }
14
+
15
+ function mouth ($ food )
16
+ {
17
+ return 'I eat ' . $ food ;
18
+ }
19
+
20
+ function eye ($ object )
21
+ {
22
+ return 'I watch ' . $ object ;
23
+ }
24
+ }
25
+
26
+ $ hafiz = new Man ();
27
+
28
+ echo $ hafiz ->eye ('Movie ' );
29
+ echo "<br/> " ;
30
+ $ mizan = new Man ();
31
+ echo $ mizan ->mouth ('Burger ' );
32
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ //oop class
3
+ class Fruit{
4
+
5
+ public $ name ; /* propertiy*/
6
+ public $ color ;
7
+
8
+ /* method or function */
9
+ public function setName ($ name )
10
+ {
11
+ $ this ->name = $ name ;
12
+ }
13
+
14
+ public function setColor ($ color )
15
+ {
16
+ $ this ->color = $ color ;
17
+ }
18
+
19
+
20
+ /* method*/
21
+ public function getFuritInfo ()
22
+ {
23
+ echo "The furit name is $ this ->name and fruit color is $ this ->color \n" ;
24
+ }
25
+
26
+ }
27
+
28
+ $ apple = new Fruit ;
29
+
30
+ $ apple ->setName ('Apple ' );
31
+ $ apple ->setColor ('Red ' );
32
+ $ apple ->getFuritInfo ();
33
+
34
+
35
+ ?>
Original file line number Diff line number Diff line change
1
+
2
+
3
+ <form action="" method="post">
4
+ <table>
5
+ <tr>
6
+ <td>Enter the first number</td>
7
+ <td>
8
+ <input type="number" name="num1">
9
+ </td>
10
+ </tr>
11
+ <tr>
12
+ <td>Enter the second number</td>
13
+ <td>
14
+ <input type="number" name="num2">
15
+ </td>
16
+ </tr>
17
+ <tr>
18
+ <td></td>
19
+ <td><input type="submit" value="Calculate" name="calculation"></td>
20
+ </tr>
21
+ </table>
22
+
23
+ </form>
24
+
25
+
26
+ <?php
27
+
28
+ include 'function.php ' ;
29
+
30
+ if (isset ($ _POST ['calculation ' ])) {
31
+
32
+ $ numOne = $ _POST ['num1 ' ];
33
+ $ numtwo = $ _POST ['num2 ' ];
34
+
35
+ if (empty ($ numOne ) or empty ($ numtwo )) {
36
+ echo "<span style='color:red'>Field must not be empty</span> <br/> " ;
37
+ }else {
38
+ echo "Frist number is : " .$ numOne . " Second number is " .$ numtwo ."<br/> " ;
39
+
40
+ $ cal = new Calculation ();
41
+ $ cal ->add ($ numOne ,$ numtwo );
42
+ $ cal ->sub ($ numOne ,$ numtwo );
43
+ $ cal ->mul ($ numOne ,$ numtwo );
44
+ $ cal ->div ($ numOne ,$ numtwo );
45
+
46
+
47
+ }
48
+ }
49
+
50
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Calculation {
6
+
7
+ function add ($ a ,$ b ){
8
+ echo "Summation = " .($ a +$ b )."<br/> " ;
9
+ }
10
+
11
+ function sub ($ a ,$ b ){
12
+ echo "Subtraction = " . ($ a -$ b ). "<br/> " ;
13
+ }
14
+ function mul ($ a ,$ b ){
15
+ echo "Multiplication = " . ($ a *$ b ). "<br/> " ;
16
+ }
17
+ function div ($ a ,$ b ){
18
+ echo "Division = " . ($ a /$ b ). "<br/> " ;
19
+ }
20
+ }
21
+
22
+ ?>
Original file line number Diff line number Diff line change
1
+
2
+ <?php
3
+ class Employee{
4
+
5
+ public $ name ;
6
+ public $ age ;
7
+
8
+ public function EmpName ($ name ="no name found " ){
9
+
10
+ echo $ this ->name = $ name ;
11
+ }
12
+
13
+ public function Age ($ age ){
14
+ echo $ this ->age =$ age ;
15
+ }
16
+ }
17
+
18
+ $ emp = new Employee ();
19
+ //$emp->name='hafizur';
20
+ $ emp ->EmpName ('Rakib ' );
21
+ echo "<br/> " ;
22
+ $ emp ->Age (25 );
23
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Calculation {
6
+
7
+ function add ($ a ,$ b ){
8
+ echo "Summation = " .($ a +$ b )."<br/> " ;
9
+ }
10
+
11
+ function sub ($ a ,$ b ){
12
+ echo "Subtraction = " . ($ a -$ b ). "<br/> " ;
13
+ }
14
+ function mul ($ a ,$ b ){
15
+ echo "Multiplication = " . ($ a *$ b ). "<br/> " ;
16
+ }
17
+ function div ($ a ,$ b ){
18
+ echo "Division = " . ($ a /$ b ). "<br/> " ;
19
+ }
20
+ }
21
+
22
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ // Define a base Employee class
3
+ class Employee {
4
+
5
+ private $ name ;
6
+
7
+ // Define a setter for the private $name property.
8
+ function setName ($ name )
9
+ {
10
+
11
+ if ($ name == "" )
12
+ {
13
+ echo "Name cannot be blank! " ;
14
+ }
15
+ else $ this ->name = $ name ;
16
+ }
17
+
18
+ // Define a getter for the private $name property
19
+ function getName ()
20
+ {
21
+
22
+ return "My name is " .$ this ->name ."<br /> " ;
23
+ }
24
+ } // end Employee class
25
+
26
+ // Define an Executive class that inherits from Employee
27
+ class Executive extends Employee {
28
+ // Define a method unique to Employee
29
+ function pillageCompany () {
30
+ echo "I'm selling company assets to finance my yacht! " ;
31
+ }
32
+ } // end Executive class
33
+ // Create a new Executive object
34
+ $ exec = new Executive ();
35
+ // Call the setName() method, defined in the Employee class
36
+ $ exec ->setName ("Richard " );
37
+ // Call the getName() method
38
+ echo $ exec ->getName ();
39
+ // Call the pillageCompany() method
40
+ $ exec ->pillageCompany ();
41
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ class Man
3
+ {
4
+ function hand ($ substance ){
5
+ return 'I grab the ' .$ substance ;
6
+ }
7
+
8
+ function leg ($ path )
9
+ {
10
+ return 'I go to ' .$ path ;
11
+ }
12
+
13
+ function mouth ($ food )
14
+ {
15
+ return 'I eat ' .$ food ;
16
+ }
17
+
18
+ function eye ($ object )
19
+ {
20
+ return 'I watch ' .$ object ;
21
+ }
22
+ }
23
+
24
+ $ hafizur = new Man ;
25
+
26
+ echo $ hafizur ->hand ('Mouse ' )."\n" ;
27
+ echo $ hafizur ->leg ('Office ' )."\n" ;
28
+
29
+ $ raihan = new Man ;
30
+
31
+ echo $ raihan ->eye ('Moive ' );
32
+
33
+
34
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class User
4
+ {
5
+
6
+ public $ name , $ password ;
7
+
8
+ function save_user ()
9
+ {
10
+ echo "Save User code goes here " ;
11
+ }
12
+ }
13
+
14
+ class Subscriber extends User
15
+ {
16
+ public $ phone , $ email ;
17
+
18
+ function display ()
19
+ {
20
+ echo "Name: " . $ this ->name . "<br> " ;
21
+ echo "Pass: " . $ this ->password . "<br> " ;
22
+ echo "Phone: " . $ this ->phone . "<br> " ;
23
+ echo "Email: " . $ this ->email ;
24
+ }
25
+ }
26
+
27
+ $ object = new Subscriber ;
28
+ $ object ->name = "Fred " ;
29
+ $ object ->password = "pword " ;
30
+ $ object ->phone = "012 345 6789 " ;
31
+ $ object ->email = "fred@bloggs.com " ;
32
+ $ object ->display ();
33
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class Employee {
4
+
5
+ public $ name ;
6
+ public $ title ;
7
+
8
+ public function __construct ($ name , $ title ) {
9
+
10
+ $ this ->name = $ name ;
11
+ $ this ->title = $ title ;
12
+ }
13
+
14
+ public function getInfo () {
15
+ echo "Employee Name is : " . $ this ->name . "<br/> " . "Title : " . $ this ->title . "<br/> " ;
16
+ }
17
+ }
18
+ $ productObject = new Employee ("Tanvir " , "Web developer " );
19
+ $ productObject ->getInfo ();
20
+ ?>
You can’t perform that action at this time.
0 commit comments