It's not fun to write PHP normally, so Born in Java (I worked in Java for about half a year) What if a human learns about PHP? I will write that.
Java background: From detailed design to unit testing, about half a year A little Java 7 ~ 8. PHP career: I used to play with Paiza and progate.
This time I moved from Java work to PHP7 work, so the difference I would like to write the part that was shocked by culture.
First of all, this was the most surprising.
In Java If you don't define a type for a variable, you'll get angry. First of all, I get angry at Eclipse's error output and compilation error.
By the way, it looks like the following
helloworld.java
public class{
public static void main(String[] args){
int i = 0;
String text = "javava";
System.out.println(i);
System.out.println(text);
}
Do this with PHP
helloworld.php
<?php
$i=0;
$text="php!php!";
echo($i);
echo($text);
>
This should probably appear on the console or somewhere else.
Overwhelming difference in code amount. I was really surprised.
This guy is still a little confused
this->Some function->Some functionやら値やら
At first I had no idea what it meant.
Think of it as Java's this.
In other words, I don't know what I'm doing because of JavaScript.
** I don't know what you're talking about ... I didn't know what I was writing ... How pretty my head was ... The sauce was dirty Indentation is messed up or spaghetti That kind of monjayaki is definitely not I tasted something more scary ... **
The state. I wonder if there is any good example I will borrow a sample of this person's page. http://saku.hateblo.jp/entry/2014/02/02/113006
This example is written in an easy-to-understand manner If this is mixed with 3 times or 4 times the amount in HTML, it will be difficult.
I'm not used to reading it, but I was pretty smart.
During study. I still don't understand. What does it mean to be able to store anything in an array? Is it a black hole or something?
Postscript: From the comment Think of it as map <string, object> in Java? I received a comment. That is correct! Thank you m (__) m
<?php
public function foo($var)
{
if ( [Conditional expression 1] ) {
return "result";
}
if ( [Conditional expression 2] ) {
return array();
}
}
It seems that you can do this. It seems that you can force types in Php7 because it is called type hinting. php is amazing.
Java graduates are also shocked by the culture of many other things. Please treat me kindly.
Recommended Posts