PHP Classes

Suggested change to depcheck_class.php

Recommend this page to a friend!

      PHP Deprecated Function Checker  >  PHP Deprecated Function Checker package blog  >  Old Dogs - New Tricks  >  All threads  >  Suggested change to depcheck_class.php  >  (Un) Subscribe thread alerts  
Subject:Suggested change to depcheck_class.php
Summary:issue with when function is first on the line
Messages:7
Author:Tony Russo
Date:2015-07-01 18:30:02
 

  1. Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Tony Russo Tony Russo - 2015-07-01 18:30:02
In depcheck_class.php

At line 101:

$position = strpos($checkLine,($this->depFunction[$x]['function'].'('));

when a function is at the beginning of the $checkLine, the $position var will be 0. When $position -1 is used on line 103 it becomes -1 (invalid index)

To work around this just after line 101 added

$position = ( $position - 1 ) < 0 ? 1 : $position;

and this seemed to work.

Or you could modifiy line 103

Change:

if( preg_match("/[a-z_]/",$checkLine[$position-1]) ){

To :

if( preg_match("/[a-z_]/",$checkLine[$position]) ){



  2. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-07-01 19:17:14 - In reply to message 1 from Tony Russo
Thanks, I will include a fix in the next update.

Dave

  3. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Tony Russo Tony Russo - 2015-07-03 16:40:09 - In reply to message 2 from Dave Smith
I've extended your original work:

1.) loadDepFile() -

a.) changed $depFunction index from integer to string to allow index by function name. Using this in an extended version of checkFile() with preg_match_all.

b.)added additional array elements.

c.) backward compatible with original base class as long as no one is using integer index with $depFunction.


2.) checkFile() -

a.) created a new function checkFile_format() derived from checkFile().

b.) Most notable change replaced strpos with preg_match_all to use regular expressions to find all instances of a functions per line.

c. using regex and string index by function name into $depFunction has better performance, don't have to iterate over each function)

d.) regex also handles optional spaces between function name and open paren "(".

e.) preg_match_all does not have the -1 index issue like strpos.

c.) added ability to store output to file.

d.) added sql query format.


3.) Work in progress

a.) add output formatting options ( html, sql, text).

b.) add mysql storage option.


Be glad to send you a copy of the extend version if you tell me where to send it.


  4. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-07-04 02:46:29 - In reply to message 3 from Tony Russo
You can send to dave at wagontrader dot com

Also send how you would like to be credited in the package should I decide to include the changes after checking them out.

Dave

  5. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Tony Russo Tony Russo - 2015-07-06 18:12:34 - In reply to message 4 from Dave Smith
Hi Dave,

Sent you an email with 4 files in a zip file.

Should be in your inbox.

Let me know if you don't get it and I'll resend.

Tony

  6. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Tony Russo Tony Russo - 2015-07-15 12:13:46 - In reply to message 4 from Dave Smith
Did you get the email?

  7. Re: Suggested change to depcheck_class.php   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-07-17 05:32:03 - In reply to message 6 from Tony Russo
I did. I have been fairly busy and have only had time to review the changes. I think I will just put your class up in its own folder with instructions for using it.

Dave