문제

Is there any way to get the caller function with something else than debug_backtrace()?

I'm looking for a less greedy way to simulate scopes like friend or internal.

Let's say I have a class A and a class B.

Until now, I've been using debug_backtrace(), which is too greedy (IMHO).

I thought of something like this:

<?php

    class A
    {
        public function __construct(B $callerObj) {}
    }

    class B
    {
        public function someMethod()
        {
            $obj = new A($this);
        }
    }
?>

It might be OK if you want to limit it to one specific class, but let's say I have 300 classes, and I want to limit it to 25 of them?

One way could be using an interface to aggregate:

public function __construct(CallerInterface $callerObj)

But it's still an ugly code.

Moreover, you can't use that trick with static classes.

Have any better idea?

도움이 되었습니까?

해결책

그래서,이를 해결할 수 없도록 화가 났을 때, SharePoint Designer의 목록을 열고 거기에서 열을 추가하기로 결정했습니다..... 그리고 그것은 문제없이 일했습니다.정상적인 SharePoint 목록 라이브러리 설정 인터페이스를 통해 작동하지 않는 똑같은 수식은 SharePoint Designer를 통해 완벽하게 작동했습니다.나는 질문하지 않을 것이다.그냥 그것을 받아 들일 것입니다

다른 팁

PHP really doesn't provide you an elegant way of handling this. Without meaning to start a language flamewar, I'm going to gingerly suggest that your design skills and needs have probably exceeded the limitations of your tool. PHP is a lightweight scripting language that's had a lot of pseudo-OOP features bolted onto it, but at its core, it wasn't ever designed for elegant enterprise architecture.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top