0

Recently I came to know that there is a slight difference in code behavior due to host platform.

$result = Data::my_custom_function($data, 'id');
//comment : my_custom_function($array, $id) --- it will return either false or string based on business logic
if($result)
{
    return $result;
}
else
{
    return false;
}

Above code runs fine with Windows if STRING is returned by function, but the same is not happening on CentOS server where the project is hosted.

It goes to else part even if there is string in $result variable.

I had to change the code to follow to have it run on both:

if(!empty($result) && is_string($result) && strlen($result) > 0)
{
    return $result;
}
else
{
    return false;
}

Why it happened I have no idea. Maybe because Windows is bit soft on strict policy like file name you can write on upper/lower case it goes without issue but in Linux kernel filename must be exactly in lower/upper case as it is on the file system. Please help.

System Info:

Both server and Local machine are equipped with PHP-7.4.x

Localhost is Windows 10

Server is Cent OS 7.x

  • Do you have a concrete example of a failing case? What happened in the failing case, which error did you face? – El_Vanja Jun 04 '21 at 10:33
  • @El_Vanja It goes to else part even if there is string in $result variable. – Hardik Trivedi Jun 04 '21 at 10:36
  • @HardikTrivedi there's no way os can affect this, are you sure that you use the same php versions on both places? – Areg Jun 04 '21 at 10:37
  • 2
    If PHP behaved differently on different systems, it would make no sense as a programming language. Have you done any debugging? Have you determined that you get the string that you are expecting to get? Does your script interact with the filesystem (since you're mentioning it)? – El_Vanja Jun 04 '21 at 10:39
  • Log `var_export($result, true)` in the `else` part to see it's exact type and value. – rustyx Jun 04 '21 at 10:40
  • @Areg same version on both machines. – Hardik Trivedi Jul 28 '21 at 08:59
  • @El_Vanja if Programming language remains same then how this happens? Also there is one more case of case sensitive files that we require. In windows it's not there and in Linux it is there. So Languages are OS independent but some of OS traits they must inherit. And we can't hide behind "OS independent" label nowadays bro. – Hardik Trivedi Jul 28 '21 at 09:02

0 Answers0