مساعدة في سؤال بلغة php
صفحة 1 من اصل 1 • شاطر
مساعدة في سؤال بلغة php
السلام عليكم ورحمة الله وبركاته .
اريد المساعدة في هذا السؤال بلغة php ومشكورين سلفا
Create a class name it friendContInfo with 4 properties with
there setters and getters
One of the properties is the phone which have to be
validate (define an utility method for this task).
• Any object of friendContInfo should be
initialized
automatically at creation time
• Add a Destructor to friendContInfo
• Add members to friendContInfo for counting the number
of object of the class has been created
اريد المساعدة في هذا السؤال بلغة php ومشكورين سلفا
Create a class name it friendContInfo with 4 properties with
there setters and getters
One of the properties is the phone which have to be
validate (define an utility method for this task).
• Any object of friendContInfo should be
initialized
automatically at creation time
• Add a Destructor to friendContInfo
• Add members to friendContInfo for counting the number
of object of the class has been created
ميرال احمد- .
- تاريخ التسجيل : 17/03/2022
المساهمات : 2
النقاط : 7
التقيم : 1
الدولة :
الجنس :
رد: مساعدة في سؤال بلغة php
الحل
- الكود:
<?php
// Define a class
class frindContInfo {
// Declaring 4 private varaibles
private $id;
private $firstName;
private $lastName;
private $Phone;
// Declarte construct method which accepts 4 parameters
public function __construct($id, $firstName, $lastName,$Phone)
{
$this->id = $id;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->Phone = $Phone;
}
public function setID($id){
$this->id = $id;
}
public function getID(){
return $this->id;
}
public function setFirstName($name){
$this->firstName = $name;
}
public function getFirstName(){
return $this->firstName;
}
public function setLastName($name){
$this->lastName = $name;
}
public function getLastName(){
return $this->lastName;
}
// Declare a method for set phone
public function setPhone($phone){
$this-> phone = $phone;
}
public function getphone(){
return $this->phone;
}
// Declare a method for validate phone
function validate_phone_number($phone)
{
// Allow +, - and . in phone number
$filtered_phone_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
// Remove "-" from number
$phone_to_check = str_replace("-", "", $filtered_phone_number);
// Check the lenght of number
// This can be customized if you want phone number from a specific country
if (strlen($phone_to_check) < 10 || strlen($phone_to_check) > 14) {
return false;
} else {
return true;
}
}
// Declare a __destruct() function.
function __destruct()
{
if ($this->validate_phone_number($this->Phone) == true) {
echo $this->id;
echo $this->firstName;
echo $this->lastName;
echo $this->Phone;
} else {
echo "Invalid phone number";
}
}
}
// Create a new object and initialized it
$object = new frindContInfo('10','ahmed','elsony','00-972-598-195-871');
?>
السنى- ........
- تاريخ التسجيل : 18/02/2011
المساهمات : 249
النقاط : 464
التقيم : 25
الجنس :
| |
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
» شركة تنظيف مسابح بالرياض
» "بروتين بعد التكميم فوائد البروتين بعد التكميم بروتين بودر بعد التكميم"
» اشهر نسخ واتساب بلس 2023 whatsapp plus
» متجر مجوهرات دير: إشراقة الذهب الخالص
» صراف صينى مقاس57*40
» فلاي تورز: اكتشف عالمًا من السفر والسياحة المثيرة
» متجر yallaa kids : مصدر الإبداع والتعلم للأطفال
» افضل تمويل
» "اقوي عروض المساج "