Anahtar Kelime yerine PHP
Örnek
insteadof
Farklı özelliklerden yöntemler seçmek için kullanın :
<?php
trait message1 {
public function msgA() {
echo
"My favorite color is red. ";
}
public function msgB()
{
echo "My favorite number is 5. ";
}
}
trait message2 {
public function msgA() {
echo "My favorite color is blue. ";
}
public function
msgB() {
echo "My favorite number is 7. ";
}
}
class MyClass {
use message1, message2 {
message1::msgA insteadof message2;
message2::msgB
insteadof message1;
}
}
$obj = new MyClass();
$obj->msgA();
$obj->msgB();
?>
Tanım ve Kullanım
Anahtar insteadof
kelime, birden fazla özelliğin aynı ada sahip bir yöntemi varsa, hangi özellikten bir yöntemin alınması gerektiğini seçmenize izin verir.
İlgili Sayfalar
anahtar trait
kelime
PHP OOP - Özellikler Eğitimimizde özellikler hakkında daha fazla bilgi edinin .
❮ PHP Anahtar Kelimeleri