A
A
Anton B2018-04-20 11:20:03
PHP
Anton B, 2018-04-20 11:20:03

Is it possible in PHP to "turn out" a function in the namespace that called it?

Hello.

// некоторый файл a.php
$a = 1;

// некоторый файл b.php
$a = 1;
$b = 2;

// некоторый файл c.php, который подключает a.php
require 'a.php'; // a.php добавляется в пространство файла c.php

// некоторый файл d.php
function my_require($name) {
    require $name.'.php'; // содержимое файла добавляется в пространство функции
}

my_require('a'); // как сделать так чтобы содержимое пространства функции развернулось в d.php?

Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil Sapegin, 2018-04-20
@ynblpb_spb

If I understand the task correctly, then the traits
php.net/manual/ru/language.oop5.traits.php will do

N
Ninazu, 2018-04-20
@Ninazu

I would strongly recommend not to use global variables. Wrap everything in a class, with a namespace and use it humanly. You can always create a static method that will return all the necessary data in any place where you need it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question