PHP 7 Migration Assistant Report (MAR)

Related tags

Laravel php7mar
Overview

Introduction

What is PHP 7 Migration Assistant Report(MAR)?

PHP 7 MAR, or just "php7mar", is a command line utility to generate reports on existing PHP 5 code to assist developers in porting their code quickly to PHP 7. It will run against invididual files or entire project folders. Reports contain line numbers, issues noted, and suggested fixes along with documentation links.

Will php7mar automatically fix my code?

No, php7mar does implement a full lexer to determine code changes and can not determine the intent of the code. It uses lexer tokenizing, string matching, and regular expressions to find syntax changes that may cause issues when porting code to PHP 7. As well, it will detect code snippets in comments and report them as it can not distinguish it as commented code.

What has changed in PHP 7? (Read This!)

If you are currently unfamiliar with what will change moving to PHP 7 then read the UPGRADING file in the current master branch of php-src. Understanding these changes is important to reading the reports generated by php7mar.

Does it handle very poorly styled code?

Very poorly styled code will not parse well, but assuming there is at least some structure to the code style it should still parse. If the code is entirely too poorly formatted there are several web sites that can be used to clean up source code.

Usage

First, start by downloading or cloning this repository. It does not need to be placed inside the folder containing the source code.

To begin, type on the command line:

php mar.php

This will produce a list of available arguments and switches.

Typical usage would appear as:

php mar.php -f="/path/to/file/example.php"

Or:

php mar.php -f="/path/to/folder/example/"

This would run against the example file or folder and save the resulting report into a reports folder inside the php7mar folder. When referencing the file or folder to run against it is recommend to use a fully qualified path. Relative paths are supported, but will be relative to the location of the php7mar folder.

Give a try, use the included testcases.php to generate a report:

php mar.php -f="testcases.php"

Available Options:

-f

	Path to the file or folder to run against.
	The location of the file or folder to use for generating the report.  A fully qualified path is recommended.  Relative paths will be based off the php7mar folder.
		*Example: -f="/path/to/folder"*

-r

	Path to the folder to save the report.
	The location to save the final report.  By default this saves into the reports/ folder inside the php7mar folder.  A fully qualified path is recommended.  Relative paths will be based off the php7mar folder.
		*Example: -r="/path/to/folder"*

-t

	Types of tests to run.
	By default all tests will run.  This option allows tests to be selected using a comma delimited list.  Allowable values: critical, nuance, and syntax.
		*Example: -t="syntax,nuance"*

-x

	List of file extension(s) to process.
	By default *.php files are processed.
		*Example: -x="php,inc"*

--php

	File path to the PHP binary to use for syntax checking.
	If this option is not used syntax checking will use the default PHP installtion to test syntax.
		*Example: --php="/path/to/php/binary/php"*

Test Types

Critical

Critical tests look for issues that will cause broken code, compilation errors, or otherwise create code that works in unintended manors.

Nuance

Nuance tests look for issues that might cause silent underisable code behavior. These tests can report many false positives as they can not determine the intent of the code being checked.

Syntax

A basic command line based syntax checker that checks all files for standard syntax issues. This is useful for double checking work after making many mass find and replace operations. Please note that syntax checking adds a significant increase to processing time especially for large code bases. To run without syntax checking use the -t option and omit syntax; -t="critical,nuance"

Comments
  • Less clutter on the report (avoiding those items that are not requiring changes)

    Less clutter on the report (avoiding those items that are not requiring changes)

    @Alexia, A wonderful tool, it has saved a lot of time - for me!

    A suggestion and a tested 'patch' to eliminate some of the "php7mar" report noise:

    Change file php7mar/classes/tests/critical.php

    -$regex = "#(?:(?:->|\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+|::\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]\(.*?\))#i";
    +$regex = "#(?:(?:\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+|(?:->|\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]|::\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]\(.*?\))#i";
    

    Before Patch Report:

    2015-07-05T20:36:10+09:30
    Scanning /root/drupal6-2015/al-orig/cck/content.module
    Including file extensions: php,inc,module
    Processed 2508 lines contained in 1 files.
    Processing took 0.039178133010864 seconds.
    
    # critical
    #### /root/drupal6-2015/al-orig/cck/content.module
    * variableInterpolation
     * Line 227: `      $node->$key = $value;`
     * Line 234: `        $node->$key = $value;`
     * Line 240: `        $node->$key = $value;`
     * Line 341: `  if (isset($node->$field['field_name'])) {`
     * Line 342: `    $items = $node->$field['field_name'];`
     * Line 351: `      $node->$field['field_name'] = $items;`
     * Line 352: `      $$this->{protocolVersion} = $version;  // peter`
     * Line 353: `      $$varname = $v;  // Peter`
     * Line 668: `        $node->$field['field_name'] = $items;`
     * Line 816: `      if (isset($node->translation_source->$field['field_name'])) {`
     * Line 817: `        $addition[$field['field_name']] = $node->translation_source->$field['field_name'];`
     * Line 943: `          if (isset($node->$field_name)) {`
     * Line 980: `        if ($field['multiple'] && isset($node->$field['field_name'])) {`
     * Line 986: `          foreach ($node->$field['field_name'] as $delta => $item) {`
     * Line 1068: `    if (!isset($object->$field) && !count($update) && isset($info['default'])) {`
     * Line 1069: `      $object->$field = $info['default'];`
     * Line 1075: `      unset($object->$field);`
     * Line 1078: `    if (isset($object->$field) || array_key_exists($field, $object)) {`
     * Line 1080: `      if (isset($object->$field)) {`
     * Line 1083: `          $values[] = $object->$field;`
     * Line 1086: `          $values[] = serialize($object->$field);`
     * Line 1110: `      $values[] = $object->$key;`
     * Line 1120: `        $object->$field = db_last_insert_id($table, $field);`
     * Line 1143: `    $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
     * Line 1158: `    if (isset($node->$field['field_name']) || count($items)) {`
     * Line 1159: `      $node->$field['field_name'] = $items;`
     * Line 1179: `      $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
     * Line 1187: `      if (isset($node->$field['field_name'])) {`
     * Line 1188: `        $node->$field['field_name'] = $items;`
    

    After Patch:

    2015-07-05T20:37:05+09:30
    Scanning /root/drupal6-2015/al-orig/cck/content.module
    Including file extensions: php,inc,module
    Processed 2508 lines contained in 1 files.
    Processing took 0.039650917053223 seconds.
    
    # critical
    #### /root/drupal6-2015/al-orig/cck/content.module
    * variableInterpolation
     * Line 341: `  if (isset($node->$field['field_name'])) {`
     * Line 342: `    $items = $node->$field['field_name'];`
     * Line 351: `      $node->$field['field_name'] = $items;`
     * Line 352: `      $$this->{protocolVersion} = $version;  // peter`
     * Line 353: `      $$varname = $v;  // Peter`
     * Line 668: `        $node->$field['field_name'] = $items;`
     * Line 816: `      if (isset($node->translation_source->$field['field_name'])) {`
     * Line 817: `        $addition[$field['field_name']] = $node->translation_source->$field['field_name'];`
     * Line 980: `        if ($field['multiple'] && isset($node->$field['field_name'])) {`
     * Line 986: `          foreach ($node->$field['field_name'] as $delta => $item) {`
     * Line 1143: `    $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
     * Line 1158: `    if (isset($node->$field['field_name']) || count($items)) {`
     * Line 1159: `      $node->$field['field_name'] = $items;`
     * Line 1179: `      $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();`
     * Line 1187: `      if (isset($node->$field['field_name'])) {`
     * Line 1188: `        $node->$field['field_name'] = $items;`
    

    This simple change avoids a number of 'unneeded' reports on the PHP Uniform Variable Syntax changes. The main target being those changed “variable variable” syntax issues = $$foo['bar'], $foo->$bar['baz'], and Foo::$bar['baz'].

    opened by peterbowey 11
  • Notice under Windows when folder contains space

    Notice under Windows when folder contains space

    As soon as the folder contains a space, I've got this notice continuously (Windows 7 with wampserver 3.0.0): Notice: Undefined index: line in D:\wamp64\\www\php7mar\mar.php on line 126

    opened by Veve2 3
  • Adding support for specifyng file extensions to consider as PHP files

    Adding support for specifyng file extensions to consider as PHP files

    I use some other file extensions for PHP files, notably .inc. I created a -x option to specify file extensions to consider PHP files. Defaults to just .php, so the default use case, commands, etc will not change.

    Ex:

        php mar.php -f=~/mycode/ 
    

    Will run looking for and processing for just ".php" files as before

        php mar.php -f=~/mycode/ -x="php,inc"
    

    Will run looking for and processing ".php" and ".inc" files

    opened by willbonde 3
  • Parse Error

    Parse Error

    When running mar.php i get the following error: PHP Parse error: syntax error, unexpected '[', expecting ')' in /usr/local/share/php7mar/mar.php on line 58

    Maybe php7mar itelf needs PHP 7? I don't see any mention of that in the readme.

    opened by lphooge 2
  • PHP4 style constructors are deprecated in PHP7

    PHP4 style constructors are deprecated in PHP7

    PHP 4 style constructors:

    PHP 4 style constructors (methods that have the same name as the class they are defined in) are deprecated, and will be removed in the future. PHP 7 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. Classes that implement a __construct()method are unaffected.

    // Methods with the same name as their class will not be constructors in a future version of PHP
    class FooBar {
            var $test = 42;
    
            function set() {}
    
            function FooBar() {
                    // NOP
            }
    }
    

    will be reported as follows:

    * oldClassConstructors
     * Line 129: `  function FooBar() {`
    

    and PHP7 will complain:

    Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

    opened by macbre 2
  • [Windows] Unable to create report

    [Windows] Unable to create report

    Hey, great project, thanks so far :) Under Windows Server there is a small problem with the name of the generated report file:

    In reporter.php at L78 (https://github.com/Alexia/php7mar/blob/master/classes/reporter.php#L78): $this->fullFilePath = $this->reportFolder.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md";

    The ':' inside the date-string lead to a filesystem error as ':' is not allowed inside file names under windows. I fixed it locally by using dots instead but maybe you can change it globally so it is working under all environments by default?

    Thanks and regards

    bug 
    opened by Cy4n1d3 2
  • Comments out lines are not ignored

    Comments out lines are not ignored

    Comments should not be scanned:

    ####/XXXXXX/XXXXXXXX.php
    * reservedNames
     * Line 99:                                                     // get class object
     * Line 179:                            // get class object
    
    bug 
    opened by virtualmarc 2
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 1
  • Add a check for new operator with reference

    Add a check for new operator with reference

    http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.new-by-ref

    Add a check for the following use of new operator which is no longer supported:

    <?php
    class C {}
    $c =& new C;
    ?>
    

    Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php on line 3

    This code will generate the following entry in the report:

    * newOperatorWithReference
     * Line 123: `$c =& new C;`
     * Line 124: `$c =&new C;`
    
    opened by macbre 1
  • Fixed: Missing '/' in manually set report path

    Fixed: Missing '/' in manually set report path

    When using the '-r' option, eg -r="/foo/bar" the report was not saved to that location. Instead all reports were saved in /foo prefixed with bar: Report located at: /foo/bar2015-12-08 ...

    This pull request fixes this issue.

    Reports are now saved to /foo/bar/2015-...

    opened by x3rAx 1
  • Markdown result changes

    Markdown result changes

    • Adds spaces between headings because some markdown parsers require that
    • Add code blocks so that it doesn't fail horribly (e.g when posting results on gihub's gist)
    opened by xPaw 1
  • I think MARS isn't working anymore

    I think MARS isn't working anymore

    I did a lot of tests and i don't find a good resolution of my problems, maybe the code has to be atualized!!

    A lot of questions of PHP 7 is ignored by de MARS, like constructs and others changes that happens into PHP 7

    Other problem is the lexical sintaxs that is not verified by MARS. In my case, is a huge project and the MARS can't be used! But the project has a nice ideia!

    opened by ChristianOliveiraSilva 0
  • added split to depricated functions.

    added split to depricated functions.

    This function was actually DEPRECATED in PHP 5.3.0.

    You can see the deprecated function list containing split in https://www.php.net/manual/en/migration53.deprecated.php under Migrating from PHP 5.2.x to PHP 5.3.x, but the function was "only" removed from php 7.0,

    Migration guide of phpmanual(5.6.x to 7.0.x) does not include this for some reason.

    opened by aghontpi 1
  • Fixed incorrectly identifying get_magic_quotes_runtime as deprecated

    Fixed incorrectly identifying get_magic_quotes_runtime as deprecated

    I'm getting results like these:

    /var/www/something/FileByteStream.php
    deprecatedFunctions
    Line 42: if (function_exists('get_magic_quotes_runtime') && @get_magic_quotes_runtime() == 1) {
    

    It looks like the script falsely identifies get_magic_quotes_runtime as being a deprecated function.

    It's not: https://www.php.net/manual/en/function.get-magic-quotes-runtime.php whereare magic_quotes_runtime is indeed deprecated: https://www.php.net/manual/en/function.magic-quotes-runtime.php

    I've extented the regex so that the target shouldn't be preceded by a underscore.

    opened by mheesters 0
  • New release? Improvements?

    New release? Improvements?

    @Alexia: I have seen improvements in several forks:

    • https://github.com/Alexia/php7mar/network

    It is possible to update the main code and solve bugs?

    Thanks in advance.

    opened by Neustradamus 0
  • `list()` detection

    `list()` detection

    It is understood that intention is not supported by this tool but since list() has changed dramatically, the tool should at least detect and report its use. The intention is not even important here. What's important is that the output from list() was reversed.

    opened by gsafcik 0
Releases(v0.2.0-beta)
  • v0.2.0-beta(Apr 26, 2016)

    Bugs

    • https://github.com/Alexia/php7mar/pull/14 - Fixed: Missing '/' in manually set report path
    • https://github.com/Alexia/php7mar/issues/16 - E_NOTICE emitted when a path contained a space under Windows.

    Features

    • https://github.com/Alexia/php7mar/pull/17 - Detect instantiating new objects by reference.
    • https://github.com/Alexia/php7mar/pull/18 - Detect PHP4 constructors
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1-alpha(Oct 27, 2015)

  • v0.1.0-alpha(Jul 22, 2015)

    • Fixed the regular expression that handles finding variable interpolation. It should now catch more specific cases that will produce less clutter in the report. Thanks to @peterbowey for reporting the issue and suggesting the fix.
    • Added a PHP binary version check. The report will now include an error message if the binary specified for syntax checks is lower than version 7.0.0-dev.
    Source code(tar.gz)
    Source code(zip)
  • v0.0.3-alpha(Jun 3, 2015)

    • Moving towards PSR-4 autoloader compliance.
      • Autoloader no longer throws an exception.
      • Namespaces are now prefixed with the vendor name.
    • Not specifying file extensions would cause a fatal error.
    • Markdown formatting tweaks for increase compatibility with various editors.
    • The scanNextFile() function was returning false for a blank file instead of an empty array. This was interrupting execution due to the scanner believing it reached the last file.
    Source code(tar.gz)
    Source code(zip)
  • v0.0.2-alpha(May 28, 2015)

    • Added -x option to specify which file extensions to use. - Thanks, @willbonde
    • Fixed a few calls that broke on PHP 5.4.
    • The reserved names check would catch examples in comments instead of checking only near the beginning of the line.
    • Composer file
    • Autoloader was using self instead of $this. Note: Autoloader is not currently PSR-4 complient due to namespaces not including a vendor name.
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1-alpha(May 22, 2015)

Owner
Alexia E. Smith
Alexia E. Smith
Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework.

Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework. This rep

LaraBug 197 Dec 9, 2022
Validate PHP database migration files for compliance with best practices. Ensure db migrations are irreversible.

PHP DB Migration Validator Introduction In modern PHP frameworks such as Symfony and Laravel, migrations usually have up and down methods. In up metho

Anton Komarev 17 Dec 14, 2022
Run patches migration style in your Laravel applications.

This package generates patch files in the same fashion Laravel generates migrations. Each file is timestamped with an up and a down method and is asso

Anthony Rappa 44 Sep 9, 2022
Magento Data Migration Tool

Overview We're pleased you're considering moving from the world's #1 eCommerce platform—Magento 1.x—to the eCommerce platform for the future, Magento

Magento 327 Jan 4, 2023
NYC Checkbook - Drupal 9 migration

Checkbook NYC Checkbook NYC is an open source financial transparency web application. Checkbook provides transparent access to a city's or other juris

Office of the Comptroller, City of New York 1 Jan 14, 2022
Make Laravel Pivot Tables using the new Laravel 9 closure migration format

This will allow you to create pivot table migration files using the new Laravel 9 closure migration format by simply passing two models.

Jose Jimenez 16 Aug 23, 2022
Laravel 4.* and 5.* service providers to handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

Laravel 4.* service provider for PHP Console See https://github.com/barbushin/php-console-laravel/releases/tag/1.2.1 Use "php-console/laravel-service-

Sergey 73 Jun 1, 2022
Public API for the project coding.events. Made in PHP 8.0 with Lumen 8, PHP-FPM, NGINX and MySQL 8.

coding.events API Uma API feita apenas para passar o tempo, montando uma API para o site <coding.events>. Sinta-se livre para usar esse código como es

Kaique Garcia 3 Oct 9, 2022
PHP phonebook with map (Active Directory, LDAP -> MySQL, PHP)

LDAP phonebook ???? ???? Development ветка Вопросы предпочтительнее задавать в Issues, а не по почте Корпоративный телефонный справочник с отображение

null 47 Nov 30, 2022
States allows you to create PHP classes following the State Pattern in PHP.

States allows you to create PHP classes following the State Pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflows writing.

Teknoo Software 10 Nov 20, 2022
PHP components - collection of cross-project PHP classes

PHP components Collection of cross-project PHP classes. Install: $ composer require ansas/php-component Ansas\Component\Convert\ConvertPrice Convert "

null 1 Jan 5, 2022
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
PHP Secure Headers

Secure Headers Add security related headers to HTTP response. The package includes Service Providers for easy Laravel integration. Version Installatio

null 431 Dec 26, 2022
A Simple GUID creator Laravel Package for PHP

A Simple GUID creator package for PHP. This package is useful for creating globally unique identifiers (GUID). It's under MIT license so it's free for

Sujip Thapa 15 Jun 26, 2021
laravel package for the Ar-PHP Project

laravel package for the Ar-PHP Project this is just a wrapper to use with laravel for the Ar-PHP Library, for more details checkout khaled-alshamaa

ATM-code 20 Dec 21, 2022
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

NetsuitePHP 6 Nov 9, 2022
Simplest Slugify for PHP to convert string into a slug.

Simplest Slugify for PHP to convert string into a slug. Documentation You can find the detailed documentation here in Slugify Documentation. Contribut

Pharaonic 6 Mar 12, 2022
PHP package to help the development of Laravel-based Telegram bots

Laravel-telegram-bot Project description goes here. This description is usually two to three lines long. It should give an overview of what the projec

CC - UFFS 6 May 10, 2021
Deploy and execute non-PHP AWS Lambda functions from your Laravel application.

Sidecar for Laravel Deploy and execute non-PHP AWS Lambda functions from your Laravel application. Read the full docs at hammerstone.dev/sidecar/docs.

Hammerstone 624 Dec 30, 2022