مساعدة في سؤال بلغة 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
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
أمس في 5:56 am من طرف wdqwd
» افضل شركة تنظيف شقق بالرياض
الخميس مايو 09, 2024 5:54 pm من طرف moslema_r
» تطبيق جوال لصيانة المكيفات
الأربعاء مايو 08, 2024 6:58 am من طرف mona mohamed
» مظلات وسواتر الرياض
الثلاثاء مايو 07, 2024 7:47 pm من طرف moslema_r
» شركة تنظيف فلل بالرياض
الثلاثاء مايو 07, 2024 6:55 pm من طرف moslema_r
» شركة تنظيف كنب بالرياض
الأحد مايو 05, 2024 6:56 pm من طرف moslema_r
» مظلات وسواتر
السبت مايو 04, 2024 8:58 pm من طرف moslema_r
» شركة تنظيف خزانات بالرياض
الخميس مايو 02, 2024 6:10 pm من طرف moslema_r
» افضل شركة رش مبيدات بالرياض
الإثنين أبريل 29, 2024 9:00 pm من طرف moslema_r
» ارخص شركة مكافحة الصراصير بالرياض
الخميس أبريل 25, 2024 8:56 pm من طرف moslema_r