Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Is it possible to write strictly typed PHP code?

user-image
Question ajoutée par Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
Date de publication: 2017/04/09
Fahmi Aijaz Aijaz
par 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

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
par Mohammed adnan , System Administrator , Zahrath Al Rawdah

yes u can write PHP typed code

Muhammad Abdullah Khan
par 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
par 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
par 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
par medhatmahmoud mahmoud , Web Designer , Connect Computer Service Co

 NO,

PHP is not strictly typed

Utilisateur supprimé
par Utilisateur supprimé

Thanks for the invitation.

I don't use PHP. Sorry :)

More Questions Like This