Spaghetti code is not what PHP is infamous for. Spaghetti code can be written in any language. PHP is infamous for all library functions being in the global scope, lack of sane naming conventions for those things, terrible type conversions, unsafe libraries, starting php with every request, being able to drop raw php right into html templates - what it was initially designed for, and being just a general web programming language not much useful in any other context. It's also got a bad wrap for being the language of choice for people who do not wish to learn any other language or anything about computer science or computers.
PHP is what happened when people learned HTML and saw that once they got to forms they needed something else.