how to check php function source code using eclipse
Asked Answered
A

3

9

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.

enter image description here

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?

Abuse answered 22/4, 2018 at 22:32 Comment(2)
array_values is an internal function, writing in C (github.com/php/php-src/blob/…)Kofu
hi @Karkouch, thanks for the comment. Do you mind if I ask, 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 codeAbuse
T
9

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.

Tova answered 8/5, 2018 at 12:45 Comment(0)
A
4

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

Abscise answered 8/5, 2018 at 12:16 Comment(0)
S
1

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 step 1

We want to search for the array_values implementation

step 2

Select the implementation in array.c

Found it

There you have it! The C implementation of array_values.

Sceptre answered 29/7, 2018 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.