public function getInstance() { if (myClass::$instance == null) { myClass::$instance = new myClass(); } return myClass::$instance; }
public static function myStaticMethodWithArgs($arg1, $arg2 = 'default') { self::$retStatic = "before myStaticMethodWithArgs\n"; sfMixer::callMixins(); self::$retStatic .= "after myStaticMethodWithArgs\n"; return self::$retStatic; }
* * The IDE includes function parameter help. Uncomment the line * below, and continue the my_function call by typing a "(" and pausing * for just a moment. * * The IDE will tell you which parameters are available to that function. * */ //echo my_function class myClass { var $size = 50; var $height = 2; function myClass() { /** * There is also popup help for class methods and variables. * Uncomment the line below and continue the call to $this->size * by typing a ">" and pausing for just a moment. The IDE will * popup the methods and functions available in this class * */ //$this- } function classFunc() { echo "Call to classFunc\n"; } } $c = new myClass(); $c->classFunc();
<?php class myClass { public $name = "Md Ariful Islam "; public $district = "Dinajpur"; public function myfunc() { echo "I am " . $this->name . "and i come from " . $this->district; } } class MyOtherClass extends myClass { public function myfunc2() { echo "I am " . $this->name . "and i come from " . $this->district; } } $object1 = new myClass(); $object1->myfunc();
public function __construct() { parent::__construct(); echo "A new contructor in" . __CLASS__ . "<br />"; }
<?php class myClass { public $name = "Jimbo"; function sayHello() { echo "HELLO! My name is " . $this->name; } } $object1 = new myClass(); $object1->sayHello(); ?>
function main_func($name, $department) { $MAX_Classes = Department::where('code', $department->code)->first()->total_rooms; //Thana kawaye nashi file read yaye ta kha /*$inputData=CSV2Array($name);//CSV2Array is a function defined inside the file functions.php and this file returns an array $i=0; foreach($inputData as $temp){//this loop will unwrap the two layered array which was stored in previous variable $inputvariable by the function CSV2Array in functions.php ${"data".$i}=$temp;//Array ko array lai unwrap gari ra cha $i++; } $courseName=$data0; $start=$data1; $end=$data2; unset($courseName[0]);//unset array na 0th item of array ta hate yana bi unset($start[0]);//This chaye yanyu dhasa tho ma yata dhasa ASP algorithm le taye mau pani chau first pseudo class miss jui so tho object yu data kha unset($end[0]);//THisis for the first column of the csv file chaye choya tayu pani mile maju $courseName=arrangeArray($courseName);//tho arrangeArray userdefined function kha... thake yo 0th item maru ta hana milaya yana bi.... ie ..A[0] delete jui hanji so A[1] ta A[0] yana bi and A[2] ta A[1] and so on $start=arrangeArray($start); $end=arrangeArray($end); */ $scheduledata = Schedule::where('day', $name)->where('department_code', $department->code)->get(); $courseName = array(); $start = array(); $end = array(); foreach ($scheduledata as $schedule) { $courseName[count($courseName)] = $schedule->course_code; $start[count($start)] = $schedule->stime; $end[count($end)] = $schedule->etime; //array_push($courseName,$schedule->course_code); //array_push($start,$schedule->stime); //array_push($end,$schedule->etime); } //File read yayau pati sidhala //For initializing the objects.... i.e. one object for one class $classes = array(); $i = 1; foreach ($start as $a) { $foo = new myClass(); $foo->set_Data($a, $end[$i - 1], $courseName[$i - 1], $i); $i++; array_push($classes, $foo); } if (count($classes)) { echo "<h2>Routine for: " . $name . "</h2><br>"; echo "The classes mentioned below are the classes that you want to arrange for <strong>" . $name . "</strong> is as below."; printObject($classes, 0, $name, $department->code); CustSort($classes); //Sorting accourding to the start time //This is the addition of A0 object at the first $temp = new myClass(); $temp->set_Data(9999, 0, "A0", 0); array_unshift($classes, $temp); //array_unshift() inserts passed elements to the front of the array //End of the A0 object addition $i = 1; while (sizeof($classes) != 1) { ${"abc" . $i} = AC_Object($classes); //$abc.$i is the array which stores the object of the classes that is being taught in the room $classes = array_udiff($classes, ${"abc" . $i}, 'compare_objects'); //This will call the functions compare_objects defined in the function functions.php so in this case the remaining classes to be arranged is ordered back $classes = arrangeArray($classes); //This will arrange the items in an array. After the removal the array will empty on certain slots for eg if array element A[7] is arranged and now it empty this gap will be arranged by this function and the new sequential function will be arranged. $i++; } //end of while for room. $i--; //this is fdone for counting the nof rooms required for the class rookm. $number_of_classes = $i; if ($number_of_classes <= $MAX_Classes && $number_of_classes > 0) { echo "You will require " . $i . " rooms for arranging this no of classes."; } else { echo "This above schedule cant be operated with existing no of classes. You will either require " . ($i - $MAX_Classes) . " additional classes or reschedule the following classes"; } $a = 1; if ($i > $MAX_Classes) { while ($a <= $MAX_Classes) { echo "<br><strong>Room: " . $a . "</strong>"; printObject(${"abc" . $a}, $a, $name, $department->code); $a++; } } //end of if($i>3 if ($number_of_classes > $MAX_Classes) { echo "The schedule you wish to prepare cant be arranged with " . $MAX_Classes . " classes. Please try to arrange the following classes in the empty slot for this day."; } while ($a <= $i) { echo "<br><strong>Room: " . $a . "</strong>"; printObject(${"abc" . $a}, $a, $name, $department->code); $a++; } } //end of if(count) }
<?php /* * Разработайте программу, которая из чисел 20..45 находила те, которые делятся на 5 и найдите сумму этих чисел. */ include 'class_for_2.php'; $a = 20; $b = 26; $c = 7; $obj = new myClass(); $n = $obj->zeroMod($a, $b, $c); if (is_array($n)) { $p = array_sum($n); echo '<br>' . $p . '<br>'; }
<?php require '../../../vendor/autoload.php'; use Ozdemir\Datatables\Datatables; use Ozdemir\Datatables\DB\MySQL; class myClass { function ajax() { include "../../_config.php"; $dt = new Datatables(new MySQL($config), $this); $dt->query("Select film_id, title, description, rating, length from film"); $dt->edit('description', "\$1", 'sample_callback(film_id), strtolower(title)'); echo $dt->generate(); } function sample_callback($data) { return "returned film id: " . $data; } } $my_class = new myClass(); $my_class->ajax();
<?php class myClass { // public property private $username; // public methods public function set_data($username) { $this->username = $username; } public function get_data() { return $this->username; } } $my_object = new myClass(); $my_object->set_data("Are you ready to learn OOP?"); echo $my_object->get_data();
public function __construct() { parent::__construct(); echo 'A New Construct in class "' . __CLASS__ . '".<br />'; }
function thrower2() { $x = new myClass(); $x->foo(); }
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class myClass { public $name; public $age; protected static $test; static function test() { var_dump(property_exists('myClass', 'age')); } } myClass::test(); class TestClass { public $declared = null; } $testObject = new TestClass(); $testObject->monkey = NULL; // kiem tra có phải 1 đối tượng cà tồn tại thuộc tính var_dump(property_exists($testObject, 'monkey'));
{ echo "yay i woke up!!!\n"; } } class zot { var $prop = array(1, 2, array("hah" => 'yoles')); } $a = array('one' => 'nine', 'string' => 'two', array(1 => 'six', array(4, 2, 1)), '2'); //$a[] =& $a; $a[] =& $globa; $a[] = 'breaker'; $a[] = $a; $a[] = $globa; $a['luck'] =& $globa; $b = test_ser($a); // test ref assignment from unserialized array $b['luck'] = 'new val'; print_r($b); $sing =& $globa; $b = test_ser($sing); $a = array('my global hi there', $globa, &$globa, 'nonref' => $globa, 'ref' => &$globa); $a[] =& $globa; test_ser($a); $c = new myClass(); $c->multi(); $d = test_ser($c); $d->p6 = 'new val'; print_r($d); $a = array('hi', &$a); test_ser($a);
public function printValue() { print "The Value is: {$this->a}\n"; } public function changeValue($val, $obj = null) { if (is_null($obj)) { $this->a = $val; } else { //$obj->a = $val; $obj->b = $val; } } public function getValue() { return $this->a; } } class mySubClass extends myClass { private $b; } $obj_one = new myClass(); $obj_two = new mySubClass(); $obj_one->changeValue(20, $obj_two); $obj_two->changeValue($obj_two->getValue(), $obj_one); $obj_two->printValue(); $obj_one->printValue(); /* FATAL ERROR: Cannot access private property */
function test_myClass() { $test_myClass = new myClass(); $result = $test_myClass->myFunction(); $this->assertEquals("data", $result); }
function DB($active_record_override = NULL) { $myClass = new myClass(); return $myClass->DB($active_record_override); }
<?php class myClass { public $name = "Jimbo"; function setName($n) { $this->name = $n; } function sayHello() { echo "HELLO! My name is " . $this->name; } } $object1 = new myClass(); $object1->setName("Julie"); $object1->sayHello();