0

PHP has a large number of batteries-included functions, e.g. functions on arrays. Some of these, like each, are present in get_defined_functions()['internal']. Others, like reset and many others, are not present at all. However, they are treated as functions in every other way: they are not documented as "language constructs" or keywords; I can call them using the "variable function" feature; function_exists("reset") returns true; if I try to redefine them (e.g. function reset() { ... }), I get an error about redeclaration, rather than a syntax error; and so on.

Why are these functions not listed by get_defined_functions? Are they not actually functions? If not, what are they? If they are functions, then what actually is it that get_defined_functions is listing? In either case, how do I list the things that don't appear in get_defined_functions?

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • Calling on the power of @Jon Skeet for this one. – Ohgodwhy Dec 22 '13 at 02:35
  • I cannot reproduce that result, http://codepad.org/1ilxgNxi, you'll see `reset` at `['internal'][576]`. Or if you want to see different php versions: http://3v4l.org/Q33FX – jeroen Dec 22 '13 at 02:52
  • No idea why this is marked as a duplicate, as it's obviously not, but whatever. The PHP mods around here seem to be extremely zealous as marking non-duplicates as duplicates! – jameshfisher Dec 22 '13 at 03:08

1 Answers1

1

Quite a short answer: Reset is present in get_defined_functions()['internal'].

Look at [1532] in this fiddle: http://phpfiddle.org/main/code/h5n-ndx

nl-x
  • 11,762
  • 7
  • 33
  • 61
  • Ah. Well. That's weird. I was using `var_dump`, you're using `print_r`. Time to find out what the difference is. – jameshfisher Dec 22 '13 at 03:03
  • Aaaarrgh. Unbelievable. `var_dump` just chops out part of the serialized data structure: "(more elements)...". What's more, there's no way to tell it that I actually want it to print the thing I said I wanted it to print. Well, I won't use that from now on, then. Thanks! – jameshfisher Dec 22 '13 at 03:07
  • @jameshfisher Also var_dump shows it: http://phpfiddle.org/main/code/fjt-rhy . Show your code that you use to output. – nl-x Dec 22 '13 at 03:08