مرحبا بالضيف ( دخول | التسجيل )

 
Reply to this topicStart new topic
مذكرة ال php5 موضوع متجدد بأستمرار
dan_alix
المشاركة Jan 13 2010, 09:38 AM
مشاركة #1


عضو نشط
***

المجموعة: Admin
المشاركات: 36
التسجيل: 13-May 08
رقم العضوية: 3



PHP notes



clone



  • __clone عند نسخ اوبجت لاخرى فأنهم يستخدمون نفس ال memory location اما عند استخدام clone فانهم يستخدمون new location مثال






كـود PHP

$tiger = new Animal();

$tiger->name = "Tiger";

$tiger->legs = 4;


$kangaroo = $tiger;

$kangaroo->name = "Kangaroo";

$kangaroo->legs = 2;

Kangaroo—2
Kangaroo—2

اما عند استخدام clone

Tiger—4
Kangaroo—2

$kangaroo = clone $tiger;

















final



بإختصار شديد فإن كلمة final إذا وضعت في بداية الدالة بداخل الـ class فإنها تعني أن هذه الدالة لا يمكن تعديلها, والمقصود بتعديلها هو أن جميع الكلاسات التي سترث من الكلاس الذي يحتوي على هذه الدالة لن يستطيعوا اعادة كتابة مره اخرى في الـ class الموروث

مثال



كـود PHP
<?php
class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}

final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}

class ChildClass extends BaseClass {
public function moreTesting() {
echo "ChildClass::moreTesting() called\n";
}
}
// Results in Fatal error: Cannot override final method BaseClass::moreTesting()
?>



اما لو حذفنا final فسيتم تعديل الدالة


في حالة إستخدمت كلمة final قبل كلمة class أثناء تعريفك للـ class فهذا يعني أنها غير قابلة للوراثة







identity operator (===),

object variables are identical if and only if they refer to the same instance of the same class.



ما هو مفهوم الـ Type Hinting ؟
هو أن تضع نوع الباراميتر قبل إسمه مثال

كـود PHP
function my_func(array $para) {
print_r($para);
}


وذلك لتفادى تحقق من نوع الباراميتر في الدالة الخاصة به وذلك بإستخدام دوال مثل is_array, is_object,is_int وما إلى ذلك
ولو كان اوبجكت نستخدم

SQL كود
function my_func(TheClass $para) {
print_r($para);
}



--------------------

Go to the top of the page
 
+Quote Post
dan_alix
المشاركة Jan 21 2010, 09:58 AM
مشاركة #2


عضو نشط
***

المجموعة: Admin
المشاركات: 36
التسجيل: 13-May 08
رقم العضوية: 3



Late Static Bindings


تستخدم للاشارة للكلاس المستدعى من التوريث والموجود فيه محتوى من نوع static وذلك عن طريق استخدام static::

can be used to reference the called class in a context of static inheritance.


مثال




<?php
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
static::who(); // Here comes Late Static Bindings
}
}

class B extends A {
public static function who() {
echo __CLASS__;
}
}


B::test();



الناتج هنا هو B اما لو تم استخدام B::test(); فسيكون الناتج A

مثال اخر لاستخدامها مع محتوى non static



<?php
class TestChild extends TestParent {
public function __construct() {
static::who();
}

public function test() {
$o = new TestParent();
}

public static function who() {
echo __CLASS__."\n";
}
}

class TestParent {
public function __construct() {
static::who();
}

public static function who() {
echo __CLASS__."\n";
}
}
$o = new TestChild;
$o->test();

?>





عندما قمنا بعمل instantiation $o = new TestChild;
تم تنفيذ ال constructor وبالتالى تم تنفيذ static::who();
والتى ستقوم بالاشارة الى الكلاس المستدعى وهو ال child

اما عندما تم تنفيذ الامر $o->test(); فسوف يقوم بتنفيذ الدالة test(); والتى ستقوم بعمل new TestParent(); والتى ستقوم بتنفيذ ال constructor الخاص بال parent وبالتالى طباعة اسم الكلاس المستدعى وهو parent


The above example will output:

TestChildTestParent
اما لز قمنا باستخدام parent او self فسوف يقوم بعمل forward الى الكلاس المستدعى









--------------------

Go to the top of the page
 
+Quote Post
dan_alix
المشاركة Jan 23 2010, 09:23 AM
مشاركة #3


عضو نشط
***

المجموعة: Admin
المشاركات: 36
التسجيل: 13-May 08
رقم العضوية: 3





Objects and references


A PHP reference is an alias, which allows two different variables to write to the same value وهذا معناه انه لو تم عمل reference لمتغير مع متغير اخر فانهم سوف يستخدمون نفس المخزن فى الذاكرة وبالتالى عند تغيير اى من احدهم فسيتم تغيير الاخر ويكون كالتالى $d = &$c;



--------------------

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 عدد القراء الحاليين لهذا الموضوع (1 الزوار 0 المتخفين)
0 الأعضاء:

 

الوقت الآن: 10th September 2010 - 02:25 AM نسخة خفيفة RSS