-3

I upgraded from php 5 to 7.2, and there is no problem at local (some changes needed, but it solved).

One of my function not working in production server. The code looks like this:

$someBool = in_array($some, array("asd", "fgh", "etc"));

If I make a var_dump on this, the result is UNKNOWN:0, but if I make a vardump exactly below this (there is no any if station before dump), the function works correctly, end the dump result will be bool (true) or bool (false).

(I don't overwrite this variable)

Again if I comment the var_dump line, the function works incorrectly.

There is anybody who has idea what can cause this behaviour? Thanks for your help.

In the original function:

$needCmdText = in_array($fieldName,array(
        'cmdpreid','cmdpostid','cmdskipid',
        'cmdfixid','cmdexpid','cmdsysid'
    ));

Where the $fieldName always 'cmdexpid' from the client. (at my test cases) And a funny news, a simple echo solve the problem too, but it should be under this.

  • The question lacks the code how "the result" is produced. Do you expect us to know your code without you sharing it? We have no idea what UNKNOWN:0 might come from. Aswell saying that `var_dump()` changes the behavior of your other code is in 99.9999% wrong – Xatenev Apr 17 '18 at 11:35
  • The code is simple, there isn't any magic in that. I simple call the in_array, and it doesn't return bool. – Benjámin Gerván Apr 17 '18 at 11:37
  • It does for me: https://3v4l.org/NhnQH [no $some] https://3v4l.org/HCKoQ [with $some] so there must be something different. – Xatenev Apr 17 '18 at 11:38
  • If I don't see, I would't belive neither, but I only uncomment and comment the var_dump, which makes different in the result. If between the var_dump and in_array there are more lines (some if) the var_dump result UNKNOWN:0, which is the result of the in_array. Some behaviour changes because of the var dump, thats for sure. – Benjámin Gerván Apr 17 '18 at 11:41
  • So will you **finally** show your code that works and the one that doesn't work? **How should we help you like this when we don't know what you wrote?** – Xatenev Apr 17 '18 at 11:42
  • Show us the input values and we might believe you. – Andreas Apr 17 '18 at 11:43
  • The problem is not because of the code, everything works fine at local. I got this only on production server (debian). Maybe the encoding change when I echo, or var_dump sg, I don't know. But if I put here the complete function which use 3-4 other function and class, you won't be closer for the solving I think. (You couldn't run anyway) – Benjámin Gerván Apr 17 '18 at 11:47
  • Okay, so we'll just stay with an unsolveable question due to too less information. – Xatenev Apr 17 '18 at 11:48
  • I can run for sure. Not very long but I can run. Now let's get back to your problem, do you want help or not? – Andreas Apr 17 '18 at 11:49
  • https://3v4l.org/agpPT it works. – Andreas Apr 17 '18 at 12:00
  • Yeah works, as I said, it works locally, but without echo or var_dump, I got the error. () I found out that it is similar to "stdClass could not be converted to int" error. But the root cause is a mistery yet. – Benjámin Gerván Apr 17 '18 at 12:21
  • If you're seeing UNKNOWN:0, that's certainly a PHP bug. However, your current code contains too little context to diagnose the issue. Please also provide the surrounding code and values used to trigger the issue. – NikiC Apr 17 '18 at 15:28
  • This is most likely due to https://bugs.php.net/bug.php?id=76281, which will be fixed in the next PHP 7.2 release. – NikiC Apr 27 '18 at 20:28

1 Answers1

0

I changed the php 7.2 to 7.1, which solved the problem without any code changing. (No need to dump, to solve).

I think there is a strange bug in php 7.2, which doesn't occure in windows environment.

  • I doubt there's a bug. You didn't post a single line of relevant code - namely, how you get the value of `$fieldName`. Downgrading is not a solution. Thinking that it doesn't occur @ Windows is not a solution. You have a gremlin lurking, it'll bite you again. – N.B. Apr 17 '18 at 12:50
  • The $fieldName is string from an array, why would change this only because I uncomment a var_dump? Nonsense, I wrote every needed information, the in_array shouldn't return UNKNOWN:0 (so it didn't return bool as expected, and didn't raise any exception or error/warning. But sure, there isn't any bug in php7.2. I couldn't reproduce this issue any development environment, that's why you couldn't reproduce neither. The production use debian, the development is under windows with xampp, the second worked fine. All I can imagine is this is a strange encoding error. – Benjámin Gerván Apr 17 '18 at 12:59
  • Sadly, developing on windows and then deploying on debian is BOUND to yield production errors. The best course of action would be to have your dev. environment equal to deployment environment and that's why tools like `vagrant` exist. I won't try to guess what's happening, the error looks like something from `xdebug`. Did you compile php on your Debian or did you install it from repo? – N.B. Apr 17 '18 at 13:18
  • I installed from repo, and the xdebug didn't run. – Benjámin Gerván Apr 17 '18 at 14:08