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

  • Home
  • SEARCH
  • 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 5947313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:56:46+00:00 2026-05-22T16:56:46+00:00

Below is a syntactically valid PHP program, which works half of the time. In

  • 0

Below is a syntactically valid PHP program, which works half of the time. In any static language, the equivalent lines would be a compile error:

<?php
class A {
 function a() { return 1; }
}

$x = new A();

if(rand(1,100) > 50) {
  print $x->b();
}
else {
  print $x->a();
}

?>

Sample output from PHP:

C:\temp>php static.php
1
C:\temp>php static.php
1
C:\temp>php static.php

Fatal error: Call to undefined method A::b() in C:\temp\static.php on line 9

Call Stack:
    0.9747     323920   1. {main}() C:\temp\static.php:0

Dynamic language proponents get all excited because, hey, this program works 50% of the time, whereas the equivalent program on a static language would fail to compile and therefore, work 0% of the time.

So, on to my question. Are there any PHP static analysis tools out there that will detect this specific class of problems?

I have read the related question: Is there a static code analyzer [like Lint] for PHP files?

But instead of trying all the tools mentioned in there one by one, I thought I’d ask a more specific question to zero-in on the one that can do this.

  • 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-22T16:56:47+00:00Added an answer on May 22, 2026 at 4:56 pm

    PhpStorm IDE can find this and many other errors in PHP-code. It’s Inspections feature of this IDE.

    example for this code

    I’m just user of this IDE, it’s not marketing 🙂

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

Sidebar

Related Questions

Below is part of the XML which I am processing with PHP's XSLTProcessor :
Below are lines from the c++ programming language template<class T > T sqrt(T );
I believe the three below are syntactically correct; but which are permitted according to
Below is my code. class Program { static void Main(string[] args) { Console.WriteLine(Main thread
Today, I have started writing a query which is as given below: SELECT IP1.InstId,CAST(IP2.Quote
Below are two different ways to initialize static readonly fields. Is there a difference
I have been pulling my hair above below snippet of code - which is
Below is my code that lets me to move the camera forward it works
Below i have a bit of code which assigns values based on the values
Below command returns with time stamp, how do I get rid of the time:

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.