Coder Social home page Coder Social logo

php7fix's Introduction

About

This script will take a single file as input and change the file so any occurrences like $this->$var() is replaced with $this->{$var}() for PHP 7 compatibility. The purpose of running this script will be to replace all such occurrences if your php-files have a lot of them and you are required to update the code to be compatible with PHP 7.

If you don't know what you're doing or are unsure about any of the expressions used here, then don't run it.

You are responsible for adding and committing any changes, this script will not do so.

I take no responsibility of anything breaking as a result of you running this.

This script assumes you're working with your code in a git-repo.

Requirements

Requires an up to date version of sed. I've used: sed (GNU sed) 4.2.2

To find the version you have, you can run: sed --version

Basic usage

Available options are: -p as in "print" and -t as in "test". Options must come before the filename.

Simple examples (one file)

All of the follwing examples will run on a single file named test.txt

The file will be changed and no output given

sh fixmethod test.txt

A git diff report will be printed for the file, but the file will be reset to it's original state (With git checkout)

sh fixmethod -pt test.txt

The file will be changed and a git diff report will be printed for the file

sh fixmethod -p test.txt

Advanced examples (multiple files)

Both these examples are run with the -tp option, meaning output will be printed and the files will be reset to their original state after running.

Removing > git.diff at the end will have the output returned to your terminal instead of being written to a file named git.diff in your folder.

Will run on all php-files in the folder and any subdirectories of it.

find . -name '*.php' -exec sh fixmethod -tp "{}" \; > git.diff

Will run on all .php-files in the folder and any subdirectories of it, EXCEPT folders ./cache and ./hooks

find . -type d \( -path ./cache -o -path ./hooks \) -prune -o -name '*.php' -exec sh fixmethod -tp "{}" \; > git.diff

Please note

The git diff will be printed for each file the command is run on regardless of whether there were any changes made by the script or not.

Also note that you may experience that running the command may change line endings or even cause git to pick up on line ending changes for files, even after git checkout on the file, if you have a .gitattributes file with options that causes this (or global options) like crlf=input

Running this may also inadvertedly change file permissions for files.

php7fix's People

Contributors

prebenlm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.