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 4021984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:25:08+00:00 2026-05-20T10:25:08+00:00

I’m looking for some tool that would do basic testing of PHP script. This

  • 0

I’m looking for some tool that would do basic testing of PHP script.

This time I’m not interested in complex testing solution that requires writing tests for each and every piece of code. I’m neither interested in functional tests.

What I expect this tool to do is to point out code fragments that might result in invalid usage of:

  1. variables;
  2. function arguments;
  3. function return values.

Invalid usage would be, for example, using NULL as an object or as an array or passing boolean as an arguent that is required to be an array or an object (or NULL).

Additionally, it might also check if “good practices” are used, i.e., it might warn that it’s not safe to use if ( $condition ) $doSomething;, if it finds something like that.


To illustrate what the tool should detect as “unsafe” code fragments, here are couple of examples.

In this case, $filter may be NULL, but it’s used as an array:

<?php
    function getList(array $filter = null) { 
        $sql = '...';
        // ...
        foreach ( $filter as $field => $value ) {
            // ...
        }
        // ...
    }

In this case, $res might be false, but it’s used as a resource.

<?php
    $res = mysql_query('...');
    while ( $row = mysql_fetch_assoc($res) ) {
        // ...
    }
    mysql_free_result($res);

And here are correspondent “safe” code fragments:

// $filter is used only if it's non-empty; as list of arguments describes, it may be only NULL or array
function getList(array $filter = null) { 
    $sql = '...';
    // ...
    if ( $filter ) {
        foreach ( $filter as $field => $value ) {
            // ...
        }
    }
    // ...
}

…

// $filter is forced to be an array
function getList(array $filter = null) { 
    $filter = (array)$filter;
    $sql = '...';
    // ...
    foreach ( $filter as $field => $value ) {
        // ...
    }
    // ...
}

…

// if $res is false, mysql_fetch_assoc() and mysql_free_result() never executes
$res = mysql_query('...');
if ( $res === false ) {
    trigger_error('...');
    return;
}
while ( $row = mysql_fetch_assoc($res) ) {
    // ...
}
mysql_free_result($res);

…

// if $res is false, mysql_fetch_assoc() and mysql_free_result() are skipped
$res = mysql_query('...');
if ( $res !== false ) {
    while ( $row = mysql_fetch_assoc($res) ) {
        // ...
    }
    mysql_free_result($res);
}
  • 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-20T10:25:09+00:00Added an answer on May 20, 2026 at 10:25 am

    This is not basic testing, but requires non-trivial analysis of the token stream.

    You can either use

    phpmd

    scans PHP source code and looks for potential problems such as possible bugs, dead code, suboptimal code, and overcomplicated expressions

    phpcs

    phpcs tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

    or – if that doesn’t suffice – look at the bytecode level with

    bytekit-cli

    bytekit-cli provides a command-line tool that leverages the Bytekit extension to perform common code analysis tasks on the PHP bytecode level.

    You will have to write you own sniffs for that.

    Further tools and resources:

    • http://phpqatools.org/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.