Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6052411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:55:33+00:00 2026-05-23T07:55:33+00:00

I used to write a very strong type language, for example, java. I need

  • 0

I used to write a very strong type language, for example, java. I need to tell the complier what type of variable I will put in… for example…

 public static void sayHello(String aName)

I can ensure that the user will pass a string to me…
But if I use php, I can do that…

 function sayHello($aName)

I still can call the sayHello, but I don’t know what the param type……I can let the name more informative like this:

 function sayHelloWithString($aName)

But I can’t stop the user pass in a int to me….. the user can still pass the int to me… …it may cause lot of errors….How can I stop it? any ideas or experience shared? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:55:33+00:00Added an answer on May 23, 2026 at 7:55 am

    There’s a few ways to deal with this…

    1. Use an IDE that supports docblocks. This deals with the pre-runtime type checking when writing code.
    2. Use type checking within your function This only helps with the runtime type checking, and you won’t know when writing your code.
    3. Depending on the type you can use built-in type hinting. This however only works for non-scalar values, specifically array and a class name.

    1 – To implement #1 using a good IDE, you can docblock your function as such:

    /**
     * Say hello to someone.
     *
     * @param string $aName
     **/
    public function sayHello($aName) {
    

    2 – To implement #2 use the is_ methods..

    public function sayHello($aName) {
        if (!is_string($aName)) {
            throw new ArgumentException("Type not correct.");
        }
        // Normal execution
    

    3 – You can’t do this with your method above, but something like this.. Kindof the same as #2 apart from will throw a catchable fatal error rather than ArgumentException.

    public function manipulateArray(array $anArray) {
    

    It’s worth noting that most of this is pretty irrelevant unless you’re writing publicly usable library code.. You should know what your methods accept, and if you’re trying to write good quality code in the first place, you should be checking this before hand.

    Using a good IDE (I recommend phpStorm a thousand times over) you can and should utilise DocBlocks everywhere you can for all of your classes. Not only will it help when writing APIs and normal code, but you can use it to document your code, what if you need to look at the code 6 months later, chances are you’re not going to remember it 100% 🙂

    Additionally, there’s a lot more you can do with docblocks than just define parameter types, look it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a program used internally where different users will have different
I need write an update statement that used multiple tables to determine which rows
Our design has one jvm that is a jboss/webapp (read/write) that is used to
I used C# before. However, after I joined in a new company, I need
I have a very large Form with many date fields that need to be
Using GWT I have a Java class: public class Pojo { private String name;
I'm completely stumped, I've used very similar code before and it worked perfectly, the
I am having a very strange deadlock in a Java application that uses two
I'm very new to Applescript but have used other scripting languages over the last
Please suggest me a good method that can be used to write a stream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.