×
Clear all filters including search bar
Valeri Tandilashvili's PHP Notes
__construct
gets called when a new object of the class gets createdclass User {
public $username;
public $friends = ['Tom','David'];
function __construct($name) {
$this->username = $name;
// print "In BaseClass constructor\n";
}
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User('George');
echo $user1->username;
class User {
public $username = 'George';
public $friends = ['Tom','David'];
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
print_r( get_class_methods('User') );
class User {
public $username;
public $friends;
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
print_r( get_class_vars('User') );
get_class
functionclass User {
public $username;
public $friends;
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
echo get_class($user1);
color
, length
, top speed
Methods (behavior): start
, stop
, accelerate
signal
try{
$stmt = $conn->prepare($query);
$stmt->execute($exec_arr);
} catch(PDOException $e) {
if($e->getCode() == 23000){
array_push($errors, 'Technology already exists');
} else {
array_push($errors, 'Database error');
}
}
$res = preg_replace('/\\\\u([a-f0-9]{4})/e', "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", json_encode($this->response));
Modern way of doing this is:$res = json_encode($this->response, JSON_UNESCAPED_UNICODE);
JSON_UNESCAPED_UNICODE
added in 5.4 PHP versioninclude_once '../../config.php';
But works one of these lines:include_once './../config.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/../config.php';
Output of the second solution is:/storage/content/95/1009995/test.sibrdzne.ge/public_html/../config.php
class a {
const OPERATOR_ID = 0;
public function test(){
echo self::OPERATOR_ID;
echo static::OPERATOR_ID;
}
}
class b extends a {
const OPERATOR_ID = 1;
}
(new b())->test();
$key
is useful outside of the foreach
loop$array = ['key1'=>1234, 'key2'=>2345, 'key3'=>3457];
foreach ($array as $key => $item) {
}
echo $key; // key3