| > You should try out other languages and you’ll see the difference I do? I work in several languages. Nothing has stood out about PHP that is worse for LLM reasoning. It's one of the most widely used languages in the world, it obviously performs pretty will with LLMs. What languages are you working in? > LLMs hallucinate array keys that don’t exist I use data objects, which are typed. PHP has types, did you not know that? If you're using raw dynamic arrays, yeah, an LLM might hallucinate keys with enough context rot. That is true of any dynamic syntax, and using raw arrays hasn't been standard practice in quite some time. > It doesn’t see, or forgets, that a string was converted to a DateTime 500 lines earlier and then makes a mistake I don't know man, this is not remotely close to my experience. Unless you were doing this like 2 years ago when LLMs were an entirely different beast. That's the only explanation I can think of for your LLM being incapable of reading 500 lines of PHP code. > It has to reason about the code from scratch every time, and in doing so it makes mistakes and wrong assumptions This sentence makes less sense the more I read it. What about PHP do you think makes LLMs "reason from scratch every time"? |
Yes I know that, please don't be an asshole. As I've said I work on a 10 million line plus PHP monolith every day. Yes, arrays are used extensively, we don't use classes for everything.
Classes also don't save you, because classes are just arrays with more steps. You can absolutely dynamically add properties to classes. Should you? No. In a legacy codebase that's 20+ years old do people do that? yes.
> That's the only explanation I can think of for your LLM being incapable of reading 500 lines of PHP code.
There's a lot of other stuff going on in those 500 lines. It's not like 500 lines of code translates into 500 lines worth of tokens. And you know that!
The LLM has to reason and think about the code. 500 lines of code could be enough to pollute the context enough.
> What about PHP do you think makes LLMs "reason from scratch every time"?
The fact that if you want to understand parts of the behavior, you have to read the code. The type system is too weak. The semantics too flexible.
Consider the following:
Is date defined here? What's the type of date? Is it a datetime, an array, a string, what? In every other language, you would know just by reading that singular line. In PHP, you can't. You need to read the entire function.What if $date was set 3 levels of nesting deep? It's function-scoped, so now it's defined. Now we have to reason about what runtime conditions can cause $date to be defined or undefined?
In C#, you don't have to do that reasoning. At all.
That's ONE tiny feature of PHP that makes it harder to statically analyze. ONE. There's hundreds of PHP features like this that just don't exist in other languages. Dynamic includes are another. I have seen classes that light up like a christmas tree in the editor. Errors, which should be criticals, everywhere.
But guess what. The class works and isn't buggy. That's not even possible in 99% of languages. But in PHP, it is, because we're including random files in different code paths and that's defining and setting variables for us.
Each of these features is, in it of itself, bad for static analysis and therefore bad for LLMs. But when you combine them together, it gets worse, more than the sum of its parts. Because now there are permutations, combinations of evil things.
PHP is just not a good language for LLMs, period. It's my experience in a very large codebase, which I can almost assure you is larger and more complex than whatever you're working on. It MIGHT work if you only stick to the most modern features and work in small codebases with tightly defined conventions. It does not work in the applications I work on. Well, I mean, it works, but just obviously not as well as dotnet or Java.