H
H
HeBonpoc2014-07-09 14:54:50
PHP
HeBonpoc, 2014-07-09 14:54:50

How to find the location of a function definition in PHP?

Conditions:
1) remote host with ssh access;
2) a lot of files, downloading them is not an option.
get_defined_functions () says that the function is defined, the interpreter does not swear at its call.
How to find where a function is defined?
Tried the following:

grep --include="*.php" -r -l "function foo_bar(" ./

I thought that in the regex, the opening bracket would be a service character, but everything is ok. I created a file with a function definition and only it was found after the command worked.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Burov, 2014-07-09
@HeBonpoc

<?php
function test() {
}

$ref = new ReflectionFunction('test');
echo $ref->getFileName().':'.$ref->getStartLine().PHP_EOL;

M
Melkij, 2014-07-09
@melkij

I thought that in the regex, the opening bracket would be a service character

So you didn't ask for a regular expression search. Flags -P or -G
grep -riP 'function\s+foo_bar\s*\('  --include="*.php" ./

O
OnYourLips, 2014-07-09
@OnYourLips

Open project in IDE and middle click.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question