If a person from Java learns PHP

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.

1. Premise

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.

2. Without a type declaration?

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.

3. There is something like a lambda expression

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.

4. I don't know what I'm doing because of HTML

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.

5. Associative array

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

6. Isn't the return type decided?

<?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.

7. At the end

Java graduates are also shocked by the culture of many other things. Please treat me kindly.

Recommended Posts

If a person from Java learns PHP
Programming beginners learn PHP from a Java perspective-variables-
Run a batch file from Java
Access Teradata from a Java application
Java, if statement / switch statement starting from beginner
Try running a Kubernetes Job from Java
From installing Eclipse to executing Java (PHP)
Access protected fields from grandchildren (Java / PHP)
Connect to Aurora (MySQL) from a Java application
To become a VB.net programmer from a Java shop
I tried hitting a Java method from ABCL
Create Scala Seq from Java, make Scala Seq a Java List
[Java] Get a random value from an array
Minecraft BE server development from PHP to Java
Ssh connect using SSHJ from a Java 6 app
How to jump from Eclipse Java to a SQL file
Call a method with a Kotlin callback block from Java
Using the database (SQL Server 2014) from a Java program 2018/01/04
[Note] Create a java environment from scratch with docker
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
[Java] How to erase a specific character from a character string
Call a program written in Swift from Processing (Java)
Generate models from JSON to Swift, PHP, C #, JAVA
JAWJAW is convenient if you use WordNet from Java
Changes from Java 8 to Java 11
Sum from Java_1 to 100
[Java] Create a filter
Eval Java source from Java
java build a triangle
Access API.AI from Java
From Java to Ruby !!
[Java] How to convert a character string from String type to byte type
Run R from a tomcat-powered Java process on Amazon Linux
How to store a string from ArrayList to String in Java (Personal)
Take a look at Kotlin from an Effective Java perspective
Get a non-empty collection from an Optional stream in java