What happens is that Javascript, not PHP, pops up an alert dialog.
So you figured out how to use PHP to output the necessary Javascript code to make something happen client-side. Congratulations; I would tell you how many times that's been done before your test case, but I imagine that the number would be very, very large.
"Lots of website[sic]" tell you that it's impossible to directly call a PHP function in an onchange field because... it is. PHP is a server-side language; all of its code is processed by a server somewhere on the planet that then spits out whatever the final result is to your browser, wherever in the world that may be. Then, the connection is severed - your browser is left to do its job, render whatever the server gave it. When your onchange event fires, it's your computer that interprets the Javascript code and executes it.