Laruence, so are you saying, that check every method's signature of a class is > *faster* than just check interface? >
Yes, yes I am saying that. And yes, the numbers show that. Think about it for a second. When you implement an interface, at compile time the compiler must loop through and check every methods signature for every interface. No matter if you ever type-hint against that interface or not. It always runs every class definition. And due to the point that opcode caches aren't caching this compilation step, it happens on every page load. So in the case where you implement an interface, but don't actually use that interface in any hints, you're still iterating through every method. My case only iterates through those methods when the hint is actually reached. So in the cases where the class never enters a hinted function/method, you wind up saving that iteration. So in that case it's significantly faster... In the case where both happens, all this does is delay the loop until run-time. So the iteration still happens (the same amount, as it happens for every unique class:interface pairing possible). In fact, the comparison is quite comparable (there are some minor differences, but not in terms of what's happening, just when it's happening). And once we have a comparison (successful or not), we cache it for the two class_entries involved. So then we never have to worry about executing it again. Therefore, structural hinting will be *worst-case* the same cost (statistically) as interfaces (it's just delaying the check to runtime instead of *every* compile). The average case (a cache hit, multiple checks of the same CE), structural will be faster as it's just a HT lookup instead of a recursive instanceof mapping. The best case (no hint), you *never* iterate through the methods in the first place. Sounds like a pretty convincing win on performance to me... Which is why it's kind of weird to keep hearing that it's slow to do, at least 6 times now in this thread... I don't need to run the test at all sigh... Anthony
