A
A
Alexander Sharomet2016-08-14 22:02:44
PHP
Alexander Sharomet, 2016-08-14 22:02:44

Why doesn't php need to specify data types?

Why do we specify data types (int, chat, string) in Java or c#, but not in php?
And what does it affect?
int a;
charb;
pho
$a, $b

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Zolotov, 2016-08-14
@sharomet

https://en.wikipedia.org/wiki/%D0%94%D0%B8%D0%BD%D...

I
index0h, 2016-08-15
@index0h

Why do we specify data types (int, chat, string) in Java or c#, but not in php?

Because php is able to independently determine the type from the input data + convert at runtime.
Starting with 7, you can specify type hinting for simple types in methods, this was the case for objects before.
In general, development in php is faster due to this, however, security suffers, therefore, up to 7, it was necessary to do a type check in each method and throw an exception if something was wrong.
Arrays - can be thought of as hashmaps, with arbitrary value types, and keys - strings/numbers. This is also kind of not quite ideologically OK, but it saves time.
Think of php as a language of quick fixes, not quick systems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question