PHP ftp_connect causing Segmentation Fault (core dumped)

Pretty strange issue and I had hard time to Google it up, so here you go, fellow PHP developers.

PHP script which was doing ftp_connect was failing on some installations with Segmentation Fault (core dumped) message. After quite a bit of time wasted looking for answers why, I found that problem was with the FTP host name having trailing line break. Well, that host name was coming from config and technically only developers had access to it, so looks like we assumed that variable “safe” and were not doing standard checks on special characters. To make things worse that line break is hard to see with debug output, because that line break is too easy to miss when you check variable value in debugger.

I am still not sure why Segmentation Fault (instead of proper message) – must be some PHP bug (and that server has Solaris OS).

Anyway, hope that helps somebody :)