Illegal Offset means what?

7 replies
Feeling kind of lost. Just trying to write what I thought would be a simple script.

Got a couple of errors on it. The error messages are:

Code:
Warning: Illegal offset type in /home/poison1/public_html/wp-content/themes/thesis_17/custom/custom_functions.php  on line 25

Warning: setcookie() expects parameter 1 to be string, object given in /home/poison1/public_html/wp-content/themes/thesis_17/custom/custom_functions.php on line 28
The function that's causing the trouble is:

Code:
function setcookielive($name="Believe_Adwords", $value=1, $expire=0, $path="/", $domain=".nickholliday.com", $secure=false, $httponly=false) {
    //set a cookie as usual, but ALSO add it to $_COOKIE so the current page load has access
    $_COOKIE[$name] = $value;
    $expire=time()+3888000;
    $value=$_GET['gclid'];
    return setcookie($name,$value,$expire,$path,$domain,$secure,$httponly);
}
Line #25 is the line that starts with $_COOKIE and line #28 is the return line.

I'm not even sure what an illegal offset is! Any help would be greatly appreciated.
#illegal #means #offset
  • Profile picture of the author amoneygame
    Well you are passing an object to the function, when it wants a string. I would try just passing "Cookie Name" like that, instead of setting the value in the function argument list as that is throwing the error.
    {{ DiscussionBoard.errors[2372814].message }}
    • Profile picture of the author Western Grizzlin'
      Originally Posted by amoneygame View Post

      Well you are passing an object to the function, when it wants a string. I would try just passing "Cookie Name" like that, instead of setting the value in the function argument list as that is throwing the error.
      I guess I still don't quite understand how you would do that? :confused:

      Also, Kirk, even though they're warnings, they must still be causing errors, because the cookie is never getting set. The other problem with the warnings is that they were showing up right at the top of my site.
      {{ DiscussionBoard.errors[2377287].message }}
  • Profile picture of the author KirkMcD
    Those are Warnings (notice how it starts with "Warning"), not errors. Unless they are causing problems they can be ignored.
    {{ DiscussionBoard.errors[2374204].message }}
  • Profile picture of the author Ken Durham
    Yeah, WP has a few plug-ins that toss out warnings.
    Actually testing if a file exists when it doesn't exist will throw a warning but this is often used.
    Signature

    yes, I am....

    {{ DiscussionBoard.errors[2376055].message }}
    • Profile picture of the author nmarley
      Originally Posted by Ken Durham

      Actually testing if a file exists when it doesn't exist will throw a warning but this is often used.
      Not if it's done right.
      {{ DiscussionBoard.errors[2376164].message }}
  • Profile picture of the author Itamar
    Hi,

    Warning are not to be ignored , if you're experienced enough.
    They might be harmful , but they might as well be deadly in cases where you want something to work flawlessly and the case comes where the warning does have a meaning.
    As the php site says , this has to do with giving an array an index which is an array.
    I would simply comment out each line , until I find out what's doing that.
    {{ DiscussionBoard.errors[2385343].message }}
  • Profile picture of the author phpbbxpert
    Filling in the functions parameters is not really the correct way of doing things either.
    Eg.

    function setcookielive($name="Believe_Adwords", $value=1, $expire=0, $path="/", $domain=".nickholliday.com", $secure=false, $httponly=false)

    Is wrong, for optional stuff like expire, httponly etc... its fine.
    But you main params where your actual passable values will go should be just $vars

    function setcookielive($name, $domain = '', $value = 1, $expire = 0, $path = "/", $secure = false, $httponly = false)
    {
    //Your function code


    Now when you call this function
    setcookielive('Believe_Adwords');

    You fill in your params.

    $_COOKIE[$name] = $value;
    Is also not correct and breaking your function.

    You are taking the cookie Believe_Adwords and trying to reassign the name to $value.

    You don't even need that line.
    The cookie name is already assigned by the first param $name.

    And $value is being assigned to whatever this $_Get is $_GET['gclid']

    Your function should look something like

    function setcookielive($name, $domain = '', $value = 1, $expire = 0, $path = "/", $secure = false, $httponly = false)
    {
    $expire = time() + 3888000;
    $value = $_GET['gclid'];
    return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
    }

    setcookielive('Believe_Adwords');

    This leaves these params
    $domain = '', $value = 1, $expire = 0, $path = "/",

    optional.

    The code block doesn't work here
    {{ DiscussionBoard.errors[2600014].message }}

Trending Topics