473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Illegal Offset & Other Assorted Errors

Got a couple of errors on a little script I'm trying to write. The error messages are:

Expand|Select|Wrap|Line Numbers
  1. Warning: Illegal offset type in /home/poison1/public_html/wp-content/themes/thesis_17/custom/custom_functions.php  on line 25
  2.  
  3. 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:

Expand|Select|Wrap|Line Numbers
  1. function setcookielive($name="Believe_Adwords", $value=1, $expire=0, $path="/", $domain=".nickholliday.com", $secure=false, $httponly=false) {
  2.     //set a cookie as usual, but ALSO add it to $_COOKIE so the current page load has access
  3.     $_COOKIE[$name] = $value;
  4.     $expire=time()+3888000;
  5.     $value=$_GET['gclid'];
  6.     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.

Any help would be greatly appreciated!
Jul 20 '10 #1

✓ answered by Dormilich

because add_cookie() does not accept parameters.

19 2386
Atli
5,058 Expert 4TB
Hey.

It would appear that you are passing the function an invalid value for the first parameter. If you add a var_dump($name) in there, what does it print?

It's always a good idea to verify input values in function like that. Especially if you plan to reuse them. It gives you better debug data, and spares the user having to see the errors.
Jul 20 '10 #2
Dormilich
8,658 Expert Mod 8TB
the second error tells you what’s up, in both lines, you feed an object instead of the expected String.
Jul 20 '10 #3
Here's what I got when I did var_dump($name):

Expand|Select|Wrap|Line Numbers
  1. object(WP)#140 (9) {
  2.  ["public_query_vars"]=>  array(47) {
  3.   [0]=>  string(1) "m"
  4.   [1]=>  string(1) "p"
  5.   [2]=>  string(5) "posts"
  6.   [3]=>  string(1) "w"
  7.   [4]=>  string(3) "cat"
  8.   [5]=>  string(12) "withcomments"
  9.   [6]=>  string(15) "withoutcomments"
  10.   [7]=>  string(1) "s"
  11.   [8]=>  string(6) "search"
  12.   [9]=>  string(5) "exact"
  13.   [10]=>  string(8) "sentence"
  14.   [11]=>  string(5) "debug"
  15.   [12]=>  string(8) "calendar"
  16.   [13]=>  string(4) "page"
  17.   [14]=>  string(5) "paged"
  18.   [15]=>  string(4) "more"
  19.   [16]=>  string(2) "tb"
  20.   [17]=>  string(2) "pb"
  21.   [18]=>  string(6) "author"
  22.   [19]=>  string(5) "order"
  23.   [20]=>  string(7) "orderby"
  24.   [21]=>  string(4) "year"
  25.   [22]=>  string(8) "monthnum"
  26.   [23]=>  string(3) "day"
  27.   [24]=>  string(4) "hour"
  28.   [25]=>  string(6) "minute"
  29.   [26]=>  string(6) "second"
  30.   [27]=>  string(4) "name"
  31.   [28]=>  string(13) "category_name"
  32.   [29]=>  string(3) "tag"
  33.   [30]=>  string(4) "feed"
  34.   [31]=>  string(11) "author_name"
  35.   [32]=>  string(6) "static"
  36.   [33]=>  string(8) "pagename"
  37.   [34]=>  string(7) "page_id"
  38.   [35]=>  string(5) "error"
  39.   [36]=>  string(14) "comments_popup"
  40.   [37]=>  string(10) "attachment"
  41.   [38]=>  string(13) "attachment_id"
  42.   [39]=>  string(7) "subpost"
  43.   [40]=>  string(10) "subpost_id"
  44.   [41]=>  string(7) "preview"
  45.   [42]=>  string(6) "robots"
  46.   [43]=>  string(8) "taxonomy"
  47.   [44]=>  string(4) "term"
  48.   [45]=>  string(5) "cpage"
  49.   [46]=>  string(9) "post_type"
  50.  }
  51.  ["private_query_vars"]=>  array(19) {
  52.   [0]=>  string(6) "offset"
  53.   [1]=>  string(14) "posts_per_page"
  54.   [2]=>  string(22) "posts_per_archive_page"
  55.   [3]=>  string(9) "showposts"
  56.   [4]=>  string(8) "nopaging"
  57.   [5]=>  string(9) "post_type"
  58.   [6]=>  string(11) "post_status"
  59.   [7]=>  string(12) "category__in"
  60.   [8]=>  string(16) "category__not_in"
  61.   [9]=>  string(13) "category__and"
  62.   [10]=>  string(7) "tag__in"
  63.   [11]=>  string(11) "tag__not_in"
  64.   [12]=>  string(8) "tag__and"
  65.   [13]=>  string(12) "tag_slug__in"
  66.   [14]=>  string(13) "tag_slug__and"
  67.   [15]=>  string(6) "tag_id"
  68.   [16]=>  string(14) "post_mime_type"
  69.   [17]=>  string(4) "perm"
  70.   [18]=>  string(17) "comments_per_page"
  71.  }
  72.  ["extra_query_vars"]=>  array(0) { }
  73.  ["query_vars"]=>  array(0) { }
  74.  ["query_string"]=>  NULL
  75.  ["request"]=>  string(0) ""
  76.  ["matched_rule"]=>  NULL
  77.  ["matched_query"]=>  NULL 
  78.  ["did_permalink"]=>  bool(false) 
"the second error tells you what’s up, in both lines, you feed an object instead of the expected String."

Unfortunately I don't understand what that means. As far as I can tell, I'm setting $name to be the string "Believe_Adwords"

I'm pretty new to script writing so you'll have to pardon my lack of context!
Jul 20 '10 #4
Dormilich
8,658 Expert Mod 8TB
As far as I can tell, I'm setting $name to be the string "Believe_Adwords"
see the first word in the output? it says "object" (and it further says, it’s of the WP class)
Jul 20 '10 #5
@Dormilich
Right, I understand that. What I'm saying is I don't understand why it would be an object when I did what my tutorials said would set a variable.

I don't even know what an object is. When I google it, all I get is stuff about object-oriented programming.
Jul 20 '10 #6
Dormilich
8,658 Expert Mod 8TB
I don't even know what an object is. When I google it, all I get is stuff about object-oriented programming.
well, that’s why it is called object-oriented programming …

how do you call the setcookielive() function?

do you use Wordpress?
Jul 20 '10 #7
Yes, I'm using Wordpress. I call the function from my "custom_function.php" file. I add it as an action to the "send_headers" part of a Wordpress page.

I previously just called the setcookie() function in this same context and everything worked great -- except that the page had to be refreshed before I could access the new cookie value.

Here's my whole custom_functions.php. It includes the old function (commented out) that worked with no problem:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Using hooks is absolutely the smartest, most bulletproof way to implement things like plugins,
  4. // custom design elements, and ads. You can add your hook calls below, and they should take the 
  5. // following form:
  6. // add_action('thesis_hook_name', 'function_name');
  7. // The function you name above will run at the location of the specified hook. The example
  8. // hook below demonstrates how you can insert Thesis' default recent posts widget above
  9. // the content in Sidebar 1:
  10. // add_action('thesis_hook_before_sidebar_1', 'thesis_widget_recent_posts');
  11.  
  12. // Delete this line, including the dashes to the left, and add your hooks in its place.
  13.  
  14.  
  15. /* Function from http://believedesign.net/php/how-to-track-customer-phone-calls-generated-through-adwords 
  16. function add_cookie() {
  17. if ($_GET['gclid']) {
  18. $expire=time()+3888000;
  19. setcookie("Believe_Adwords",$_GET['gclid'],$expire,"/",".nickholliday.com");
  20. }
  21. }
  22.  
  23. add_action('send_headers','add_cookie'); */
  24.  
  25.  
  26.  
  27. /* Function to make cookie go live on the first load of page */
  28. function setcookielive($name="Believe_Adwords", $value=1, $expire=0, $path="/", $domain=".nickholliday.com", $secure=false, $httponly=false) {
  29.     //set a cookie as usual, but ALSO add it to $_COOKIE so the current page load has access
  30.     $_COOKIE[$name] = $value;
  31.     $expire=time()+3888000;
  32.     $value=$_GET['gclid'];
  33.     return setcookie($name,$value,$expire,$path,$domain,$secure,$httponly);
  34.  
  35. add_action('send_headers','setcookielive'); 
  36.  
  37.  
  38. /* Function from http://believedesign.net/php/how-to-track-customer-phone-calls-generated-through-adwords */
  39. function get_phone_number($atts) {
  40.     echo (isset($_COOKIE['Believe_Adwords'])) ? '555-0968-5566' : '555-8979-4567';
  41. }
  42.  
  43. add_shortcode('get-phone-number','get_phone_number');
  44. ?>
Jul 20 '10 #8
Dormilich
8,658 Expert Mod 8TB
what does the add_action() function do?
Jul 21 '10 #9
I believe add_action() is a wordpress thing that tells wordpress where in the page to insert your function.

So in my theme, I could have done

Expand|Select|Wrap|Line Numbers
  1. add_action('add_cookie','thesis_hook_after_header');
and that would have put that function after my page header. Of course it wouldn't have worked because I have to set the cookies in the http headers.
Jul 21 '10 #10
Dormilich
8,658 Expert Mod 8TB
the add_action() function is responsible, why you have an object instead of a string.
Jul 22 '10 #11
In that case, why would the add_cookie() function work fine, but the setcookielive() function doesn't?
Jul 22 '10 #12
Dormilich
8,658 Expert Mod 8TB
because add_cookie() does not accept parameters.
Jul 23 '10 #13
Why didn't you say so! :)

I was able to solve my problem. Thank you for your help!

So, a function with parameters is an object, but a function without parameters is not?
Jul 23 '10 #14
Markus
6,050 Expert 4TB
@Nick Holliday
No. A function with parameters is a function with parameters. A function with no parameters is a function with no parameters. An object is an instance of a class.

Expand|Select|Wrap|Line Numbers
  1. // Just a function
  2. function say_hello() 
  3. {
  4.   echo 'Hello!', PHP_EOL;
  5. }
  6. // Again, just a function
  7. function say_hello_ex($greeting) 
  8. {
  9.   echo $greeting, PHP_EOL;
  10. }
  11.  
  12. // A class
  13. class Person 
  14. {
  15.   private $name;
  16.   private $age;
  17.  
  18.   public function __construct($name, $age)
  19.   {
  20.      $this->name = $name;
  21.      $this->age  = $age;
  22.   }
  23.   public function getName() { return $this->name; }
  24.   public function setName($name) { $this->name = $name; }
  25.   public function getAge() { return $this->age; }
  26.   public function setAge($age) { $this->age = $age; }
  27. }
  28.  
  29. // An object: an instance of a class.
  30. $person = new Person('Mark', 19);
  31.  
  32. printf("Person's name: %s, Age: %d\n",
  33.     $person->getName(),
  34.     $person->getAge()
  35. );
  36.  
  37. say_hello();
  38. say_hello_ex("Greetings, " . $person->getName());
  39.  
Mark.
Jul 24 '10 #15
Thanks for that explanation.

Does that mean that in the following code that $name had been defined as an object (I understood Dormilich to say it was an object) elsewhere on my wordpress site?

Expand|Select|Wrap|Line Numbers
  1. # function setcookielive($name="Believe_Adwords", $value=1, $expire=0, $path="/", $domain=".nickholliday.com", $secure=false, $httponly=false) {
  2. #     //set a cookie as usual, but ALSO add it to $_COOKIE so the current page load has access
  3. #     $_COOKIE[$name] = $value;
  4. #     $expire=time()+3888000;
  5. #     $value=$_GET['gclid'];
  6. #     return setcookie($name,$value,$expire,$path,$domain,$secure,$httponly);
  7. # } 
Jul 24 '10 #16
Dormilich
8,658 Expert Mod 8TB
no. that’s the doing of add_action(). that function is passing a WP object as first argument to setcookielive().
Jul 24 '10 #17
@Dormilich
so send_headers() is an object?
Jul 24 '10 #18
Dormilich
8,658 Expert Mod 8TB
the 'send_headers' in
Expand|Select|Wrap|Line Numbers
  1. add_action('send_headers','add_cookie');
is a string. but unless I know how add_action actually works, I can’t tell you, what’s passed to add_cookie() and why. I only can assume that it is some kind of event which is part of WordPress.

to give an analogy, in JavaScript, event handlers pass an event object as parameter to the function. (note the similarity in the calls)
Expand|Select|Wrap|Line Numbers
  1. function doSomething(a)
  2. {
  3.     alert(a);
  4. }
  5. window.addEventListener("load", doSomething, false);
  6.  
  7. // should show something like
  8. // [object Event]
Jul 24 '10 #19
Jyoti Ballabh
115 100+
thanks for the solution folks, I was facing a problem akin to this one.
Jul 25 '10 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Miguel Orrego | last post by:
Hi, I am trying to migrate an asp app from an NT4 Server to a Win 2k Server. The directory structure & DSNs have been copied over and IIS configured in the same way as the old server. ...
4
by: Chris Sharman | last post by:
I've a very simple page (intranet, but moved to http://services.ccagroup.co.uk/dtest.html for you - so the links are all broken). essentially it's just a list of links. I've split it into two...
0
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two...
0
by: Richard Beacroft | last post by:
Trying to write a C# Windows App to export all objects and content from 2 MSAccess 97 databases for comparison analysis. very little documentation found. Have managed to instantiate MSAccess,...
0
by: Sushma | last post by:
CSiFtpConnection error LNK2001: unresolved external symbol "public: virtual class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __thiscall...
1
by: Manish | last post by:
The code is as ... $folderlistfile = $path."xmlfile.xml"; /* <list> <details id="2"> <name>Books</name>
1
by: Jim Frazer | last post by:
Hi, I've just encountered a bunch of errors when loading a form in design mode. These errors have not occured before and don't make sense to me. In addition, none of my controls are displayed...
2
by: ErikL | last post by:
Hey, I am looking for a list of illegal characters in XML.. For example: è, À, ì are illegal characters. They could errors. I am looking for a massive list of these so we can filter them out for a...
1
by: prw8864 | last post by:
In the following code I am trying to create a new templete class (SVector) that is a linked list with the added functionality of an insert method that automatically places items in sorted order. I...
1
by: chazzy69 | last post by:
Currently working on a site that has user and admin access. Now basically im trying to use - $file1 = file_get_contents($url); The file im trying to retrieve is only accessible via logining...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.