0

This is just for easier to track and read the code, I want my php code follow what the Java did.

For example:

foreach($objects as  $object){
 do something with $object . 
}

I want the $object is clear what kind of object is it ...

I tried foreach($objects as (ClassOfSomething) $object):

but it produced error ...

I want my code easy to read and the object recognized by the IDE directly (I am using Intellij Idea btw)

6
  • 1
    PHP doesn't use static typing, it figures out the type dynamically. Commented Jul 15, 2014 at 10:09
  • 1
    If you want to document the types of variables, use phpDoc. Commented Jul 15, 2014 at 10:10
  • Why are you using Intellij Idea for PHP? It's a Java IDE isn't it? Commented Jul 15, 2014 at 10:25
  • 1
    @vascowhite IntelliJ IDEA is an IDE written in Java but supporting many languages via plugins, including PHP. JetBrains, the company behind IntelliJ produce also PhpStorm, an IDE dedicated to PHP development, but it is basically a selection of plugins that could be manually installed into IntelliJ too. Commented Jul 15, 2014 at 10:55
  • 1
    Yes, I use PHPStorm. I just thought idea was Java only. I was probably confused by the web site "The Most Intelligent IDE for the Java Platform". :) Commented Jul 15, 2014 at 11:08

1 Answer 1

1

You can add this phpDoc comment before the loop:

/** @var ClassOfSomething $object */

This is in standard phpDoc format, and most IDEs, including IntelliJ pick this up and use it for autocompletion etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.