how to check php function source code using eclipse - php

I'm curious on how certain php functions are implemented internally. e.g. array_values().
So in eclipse, I control click on the function name, which took me to a page that contain function prototype definition, but contains no internal source code.
Is there any way to see the internal implementation of php function using eclipse? (whether the function is written in php or c)
If it is not possible to see the php source code using eclipse, then does anyone have any good strategies at searching through the php source code on github?

Is there any way to see the internal implementation of php function using eclipse?
Unfortunately, no.
what is the best search strategy to search through the php source code, especially for a beginner like me, who feels very much lost in the vast amount of php source code
I'm assuming what you are really after here is a reference for native PHP functions and their input parameters and out types. In which case the official documentation is probably the best way to go about it.
Some (most?) popular IDEs such as Eclipse and Phpstorm can also give you an auto-generated phpdoc block for PHP's built-in functions that will give that information directly in your IDE.
If you are interested in the actual C implementation of most php functions, you can either navigate through the GitHub repository directly or clone it on your computer and open it in an IDE (Eclipse, CLion, etc...) and use the IDE navigation.

You can download the PHP source code from GitHub (https://github.com/php/php-src)
but the core of PHP is written in C language.
Use notepad++ to search the required details from the downloaded source code.
For example code for PHP array will be in this file :
https://github.com/php/php-src/blob/master/ext/standard/array.c
Notepad++ is the good editor with a lot of additional functionality like search string through files. (Find in files)
Hope it helps
Thanks

As an alternative, consider running OpenGrok in a Docker container. OpenGrok is an open-source and free source code indexer with advanced search mechanisms. (I am not affiliated with the project in any way)
Setting it up is easy (assuming you have Docker already installed):
# Make a directory that will contain source files for opengrok to index
mkdir ~/opengrok
# Clone the PHP source into that directory
git clone https://github.com/php/php-src.git ~/opengrok/php-src
# Start the OpenGrok container
docker run -d -v ~/opengrok:/src -p8081:8080 opengrok/docker
Now you should wait a minute or two for OpenGrok to fully index the source tree.
Open your browser
We want to search for the array_values implementation
Select the implementation in array.c
There you have it! The C implementation of array_values.

Related

Minify PHP in Visual Studio 2015

Is there any way to minify (or remove comments) in PHP using Visual Studio 2015? I use PHP Tools and when i release php scripts to public server, i would like at least remove all comments from code. I know, is there way to remove comments with content menu, but i wish to have comments in my project and no comments (or minimal and unread code) in publish scripts (some like Bundler & Minifier tool, but for php). Thanks
There is basically no point in minifying Php since there is no performance gain in doing so. Although if you insist, there are a few ways to remove comments/whitespaces from source. (and these are not limited to just VisualStudio) -
Use Gulp.
Use Command line options: php -w file.php => generates file without comments & whitespaces. Equivalent to php_strip_whitespace()
Use Regular Expression in Find-Replace Function of your IDE. You can use the following inside Find FieldBox. (and keep Replace fieldbox empty)
//.* or /.
Use a Library/tool like Php-Minify
Hope that helps!
Why aren't you going to use online tool to do it?
There are many online tools you can use instead of VS 2015.
Here is one tool for you.
http://beta.phpformatter.com/
Hope it helps you and check this answer as solved if it helps you.
Thanks!
You can check Comment Remover tool to remove all the comments from a file with a single button click. It also remove #regions and preserve XML Doc comments.
I think there is no tool for visual studio to do this. But you may use external tools to do the job. It's a common task to do this in build system like jenkins. The build system e. g. is able to react on many version control events.
But I also think that you want to make php code unreadable (like compiling). There are only a few options to hide your php code to other people. You could use ionCube for encrypting php files. But then you have to make sure, that the ionCube extension is also installed on the public web server. Also, ionCube is currently not available for php 7.2, only up to 7.1. Another option is to compile php code using HipHop, a PHP to C++ compiler engine: https://de.wikipedia.org/wiki/HipHop

How to ask Jenkins detect restricted words in source code and fail build?

I have Jenkins CI.
Source code is PHP.
Jenkins grabs every 5 minutes source code from GIT.
How to configure to scan source code for resticted words:
sqlsrv_
mssql_
I need it to monitor another developers to avoid using deprecated functions in code.
What you need is a static code analysis tool for PHP. Then you need to configure Jenkins to launch that tool.
There are tons available.
Here is a question listing many static code analysis tools for PHP:
Is there a static code analyzer [like Lint] for PHP files?
Here is a question about linking one of those (PHP Code Sniffer) with Jenkins:
Using Jenkins and Php Code Sniffer
I would suggest you define Sniffs (Custom based sniffs) and those can grab The mentioned words whenever they appear. You can then make your build fail or display error message accordingly.
I have been able to create my own Sniffs after seeing how Sniffs are developed in:
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
Hope this helps.

How to compile php without unneeded functions to a single file?

I'm trying to create a very small php binary for a specific use. I don't need many of the functions and classes included in commong php. How can I do this?
Thanks.
Checkout php source form svn or download source dist on php.net and build it using manual. It is better to do it on nix systems or compile PHP with cygwin on Win. You can easy configure php extensions when building it and exclude some of it using configure script. If you need more specific configurations you should know how Autotools works couse php uses it.

How to find a correct php file to edit in large live running web system?

I have a huge live running web site wich has lot of issues. This has developed by lot of programmers around the world. So If I want to fix some errors its really hard to find where it is and so on....These files are in zend framework. There are 100s of php files, css files java sripts files, etc. Is there any way that I can do global search a file or how to understand the file linkage of this kind of large systems?
If you are using Linux there are a bunch of ways to find the correct file -
On the command line
Find a file by name -
find . -name filename
Or the faster find a file by name -
sudo updatedb #Only needed the first time you run locate
locate filename
Search a directory's contents recursively for a string -
grep -ri somestring .
Here's a new trick I learnt recently - Using Ack! If you are on a Debian/Ubuntu system you can install ack by doing -
sudo apt-get install ack-grep
Then you can do -
ack-grep somestring
This is blazing fast!
In IDEs
In most IDEs or advanced editors you should be able to simply control click or right click and select "go to definition" to navigate to a function's definition.
I can attest that this works in Netbeans, Eclipse, Komodo, Emacs etc.
If you are open to adopting a new IDE, I suggest Netbeans. It's PHP mode is full of goodies including improved navigation. For example, to quickly open a file you can simply do Alt-Shift-O and type the filename.
First of all I think you'll need to learn a bit about Zend Framework, how it's MVC framework works and where the models, views and controllers are stored. This'll help you guess where to go looking for problems.
In terms of searching for specific lines of code or patterns most operating systems or IDEs will allow you perform a recursive search of a set of files. I think that's outside the scope of this site.
if you are using aptana you can search your whole workspace by going to search->search. If you are using dreamweaver you can open find menu and search through your current site
It will be pretty hard to locate the right file in a quick way if you don't have any knowledge about the application at all. I would recommend reading up on Zend Framework and how it's working.
debug_backtrace() can come in handy if you need to show a backtrace. This can be useful if you need to know from where a function has been called.
If you're searching for a file that outputs something, a simple "search all directories, recursive" search will probably do just fine. Most IDEs (even "simple" one like Notepad++) or even OSes have this built in.

Find PHP Orphan Page

I've inherited a PHP application that has "versions" of pages (viewacct.php, viewacct2.php, viewacct_rcw.php, etc). I want to discover which of these pages are called from other pages in the application and which are not. Is there a tool available that will help with that?
Using whatever tools you would like (Find/Grep/Sed on Linux, I use Visual Studio on windows), it is just a matter of crawling your source tree for references of the filenames in each file.
Similar to FlySwat's answer: any good text editor or IDE with multi-file search should be able to help you find the orphan pages. On Mac OS X I would suggest TextWrangler(free), TextMate($), or BBEdit($$). I've had good success with each of these tools, but your mileage may vary.
If you wish to find out what pages are called by other pages, you need to look at where stuff is being called. Obviously in php code, you can only reference other files via includes or requires and the singular versions of those functions.
So if I were you I would grep your code for include and then require and attempt to make some kind of map showing what is calling what. Eventually you should end up with a pretty clear map of how the php files talk to each other. Then you will need to work out how the various points of the application talk to each other from there via HTML/AJAX etc.
Good luck. I have done it before, it takes a while, but you'll get there, just make sure you document what you find out.
You may want to try out nWire for PHP.
nWire for PHP is an innovative Eclipse plugin (works with Eclipse PDT & Zend Studio 7) which accelerates PHP development by helping developers navigate through their code and better understand the architecture of their application. nWire offers unique tools for real time code visualization, navigation and search.
nWire analyzes all the components and associations in your project. While opening a file you can immediately see where (and if) it is being used.

Categories