ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Is it possible to write strictly typed PHP code?

user-image
تم إضافة السؤال من قبل Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
تاريخ النشر: 2017/04/09
Fahmi Aijaz Aijaz
من قبل Fahmi Aijaz Aijaz , Tata classedge coordinator , 2 coms consulting

it is possible to write strict typed code which means when we declare value of a variable it

automatically converts it into that data type

like  $a='abc' value abc will automatically converted to string value

BK Shah
من قبل BK Shah

First thing is that it depends on your knowledge and experiences in my experiences i could write strict code or week code as well. In new php7 you can declare data type like scaler type, return type etc.

Science php known as week then others programming like C, C++, C#, python but the is not what makes php bad world most used programming language is php. But is you wish you can customize you code. Since php7 for example you can define

<?php

declare(strict_types=1);

//Rest of your code here

?>

if you would not like to use strict type then you can disable. PHP7 new feature has made php more reliable and you can use as per your need and requirement.

Mohammed adnan
من قبل Mohammed adnan , System Administrator , Zahrath Al Rawdah

yes u can write PHP typed code

Muhammad Abdullah Khan
من قبل Muhammad Abdullah Khan , Software Developer , Karakeeb Outlet

Yes! In short it is possible. PHP is an OOP language and some of the things are optional. Optional means that you may or may not use them. If you want to use them no one is stopping you. So it is possible to write strict code in PHP.

 

alaa liswe
من قبل alaa liswe , ِAdministrative Assistant , Arab Open University

No. There is support for type hinting since php5 , but "Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported."

Mohamed Ali
من قبل Mohamed Ali , Senior Online Developer , Al Arab News Channel

PHP is loosely-typed language which is mean that you can use a variable without declaring it. If a variable is used to store integer  that mean still access integer as string and reverse is possible too :). Anyway PHP manages that automatically. 

 

I advise you to read the Wikipedia article for Strong and weak typing

medhatmahmoud mahmoud
من قبل medhatmahmoud mahmoud , Web Designer , Connect Computer Service Co

 NO,

PHP is not strictly typed

مستخدم محذوف‎
من قبل مستخدم محذوف‎

Thanks for the invitation.

I don't use PHP. Sorry :)

المزيد من الأسئلة المماثلة