Results: 135
Magic method
__destruct
gets called when we delete an object manually. If we don't delete the object during the code execution, it will be called automatically at the end of the code execution
class User {
    public $username;
    public $friends = ['Tom','David'];

    function __construct($name) {
        $this->username = $name;
        print $this->username . "'s object is created'\n";
    }

    function __destruct() {
        print $this->username . "'s object is deleted'\n";
    }
}
$user1 = new User('George');
$user2 = new User('David');
echo $user1->username . "\n";
Magic method
__construct
gets called when a new object of the class gets created
class 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;
Returns a list of methods of the class being passed to the function
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') );
Returns an array with properties of the class
class User {
    public $username;
    public $friends;
    
    public function addFriend($friend_name) {
        $this->friends[] = $friend_name;
    }
}
$user1 = new User();
print_r( get_class_vars('User') );
Returns the name of the class that is used to create the object passed to the
get_class
function
class User {
    public $username;
    public $friends;
    
    public function addFriend($friend_name) {
        $this->friends[] = $friend_name;
    }
}
$user1 = new User();
echo get_class($user1);
Properties (attributes):
color
,
length
,
top speed
Methods (behavior):
start
,
stop
,
accelerate
signal
PDO duplicate entry error code
We get the error code (using DB unique constraint) when the resource is already created
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 version
include resource
The statement does not work when config.php is one step out of the root directory on servage.net
include_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
SMPP SMS-Off UTF8 Support CODE
function getString(&$ar, $maxlen = 255, $firstRead = false, $encoding = 3)
{
	$s = "";
	$i = 0;
	$rep = 1;
	if ($encoding == 8) {
		$rep = 2;
	}
	do {
		$c = 0;
		for($rc = 0; $rc < $rep; $rc ++) {
			$c += ($firstRead && $i == 0) ? current($ar) : next($ar);
			$i++;
		}
		if ($encoding == 8) {
            if ($c >= 224 && $c <= 256) {
                $c += 4080;
            }
		}
		if ($c != 0) {
			$s .= mb_chr($c);
		}
	} while ($i < $maxlen && $c != 0);
	
	return $s;
}

$ar = unpack("C*", hex2bin('0001013939353539383235313533340000013930323237000000000000000008004a004800650079002010d010d110d210d310d410d510d610d710d810d910da10db10dc10dd10de10df10e010e110e210e310e410e510e610e710e810e910ea10eb10ec10ed10ee10ef10f00204000200a2'));

$service_type = getString($ar, 6, true); // 6

$source_addr_ton = next($ar); // 7
$source_addr_npi = next($ar); // 8
$source_addr = getString($ar, 21); // 29

$dest_addr_ton = next($ar); // 30
$dest_addr_npi = next($ar);
$destination_addr = getString($ar, 21); // 52

$esmClass = next($ar);
$protocolId = next($ar);
$priorityFlag = next($ar);
next($ar); // schedule_delivery_time
next($ar); // validity_period 
$registeredDelivery = next($ar);
next($ar); // replace_if_present_flag 
$dataCoding = next($ar); // 60
next($ar); // sm_default_msg_id 
$sm_length = next($ar);
$message = getString($ar, $sm_length, false, $dataCoding);

var_dump('encoding: '.$dataCoding, 'length: ' . $sm_length, 'msg:' . $message);
Results: 135