Thread: str_pad warning

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    str_pad warning


    My cronjob has starting giving me the following warning:

    Warning: str_pad() expects parameter 4 to be long, string given in ....

    it references the following lines of code:

    $lastphotoname = $filedirectory . $filename . "_" . str_pad($lastphotonum, 7, "0", STR_PAD_LEFT) . ".jpg";

    $nextphotoname = $filedirectory . $filename . "_" . str_pad($nextphotonum, 7, "0", STR_PAD_LEFT) . ".jpg";

    Any ideas as to why I get the warnings ?

    It appears that my host upgraded the php version to 5.3.19 the day before my warnings started to appear .... but not sure why that would have anything to do with it ......

    Thanks,
    JerryB
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    What does
    PHP Code:
    var_dump(defined("STR_PAD_LEFT")); 
    output?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0
    It outputs:
    bool(true)
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    Are you absolutely sure that the error is recent and coming from exactly those two lines? And that the code is exactly what you posted? Please check again. Because PHP just told you that those constants do exist; if they didn't then PHP would treat them as literal strings (with a warning) causing the error you see.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0
    My cronjob has been running 4 times a day for over a year and never complained - then several days ago I started getting this message ....

    Sometimes when I get an error the lines don't always match up with the line numbers I see in TextWrangler but in this case I am sure in that these two lines of code are the only two lines of code that use str_pad ....

    I cut and pasted the code right out of my source code ... so it is definitely the correct code ....

    Like you - it doesn't make sense to me either .....

    The code changes the home page picture on my website - rotating amongst 11 pictures - it has been changing the picture that whole time and what is weird is that it still is - so does this error not actually stop the code from executing correctly ? Could it be that it has always had this warning and the host site just turned on the piece that gives me my errors ? But even so - what is the warning about - the code looks perfectly fine to me -
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    Yeah, it could be that the new installation just changed the error reporting settings. Actually that happens very often - we regularly see people who tell of brand new errors in scripts that were working "perfectly" before.

    But in your case I don't see anything wrong... No offense but past experience tells me that there's something important you're not telling us (unintentionally, I'm sure).

    If you try running the file manually yourself does it still complain? And perhaps a more obvious question, what does
    PHP Code:
    echo STR_PAD_LEFT
    output and are there any errors with it?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0
    ran the code manually and it ran fine - no errors

    the echo str_padLeft returned: 0

    what is even weirder is that the next time my routine ran from the cronjonb it did not send me any warnings .... just as they mysteriously started appearing, they have mysteriously disappeared ..... maybe it had something to do with Mayans

    any thoughts .....

IMN logo majestic logo threadwatch logo seochat tools logo