{"id":22,"date":"2008-08-16T12:46:37","date_gmt":"2008-08-16T16:46:37","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=22"},"modified":"2008-08-16T12:46:37","modified_gmt":"2008-08-16T16:46:37","slug":"stopping-php-fatal-error-internal-object-missing-in-error-in-php-gtk2","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2008\/08\/16\/stopping-php-fatal-error-internal-object-missing-in-error-in-php-gtk2\/","title":{"rendered":"Stopping the &#8220;PHP Fatal error:  Internal object missing in&#8221; error in PHP-GTK2"},"content":{"rendered":"<p>In PHP-GTK2, if you build your own class of an existing PHP-GTK2 class, you may encounter one of the following errors:<\/p>\n<ul>\n<li>&#8220;PHP Fatal error:\u00a0 Internal object missing in <span style=\"font-style: italic;\"><span style=\"font-weight: bold;\">YourclassName<\/span><\/span> wrapper in <span style=\"font-style: italic;\"><span style=\"font-weight: bold;\">\/path\/to\/your\/script<\/span><\/span> on line *&#8221;<\/li>\n<li>&#8220;Fatal error: Internal object missing in <span style=\"font-style: italic;\"><span style=\"font-weight: bold;\">YourclassName<\/span><\/span> wrapper in <span style=\"font-style: italic;\"><span style=\"font-weight: bold;\">\/path\/to\/your\/script<\/span><\/span> on line *&#8221;<\/li>\n<\/ul>\n<p>This is somehow (not documented) caused by not calling <span style=\"font-weight: bold;\">parent::__construct()<\/span>, the parent constructor. For example, try to run the following snippet:<br \/>\n<code><span style=\"color: #000000;\"><span style=\"color: #0000bb;\">&lt;?php<br \/>\n<\/span><\/span><\/code><span style=\"color: #007700;\">if\u00a0(!<\/span><span style=\"color: #0000bb;\">class_exists<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8216;gtk&#8217;<\/span><span style=\"color: #007700;\">))\u00a0{<br \/>\ndie(<\/span><span style=\"color: #dd0000;\">&#8220;ERROR:\u00a0No\u00a0PHP-GTK2\u00a0Module.\\n&#8221;<\/span><span style=\"color: #007700;\">);<br \/>\n}<\/span><\/p>\n<p>class\u00a0<span style=\"color: #0000bb;\">Myclassw <\/span><span style=\"color: #007700;\">extends <\/span><span style=\"color: #0000bb;\">GtkWindow <\/span><span style=\"color: #007700;\">{<br \/>\n<\/span>protected\u00a0<span style=\"color: #0000bb;\">$label<\/span><span style=\"color: #007700;\">;<\/span><\/p>\n<p>function\u00a0<span style=\"color: #0000bb;\">__construct<\/span><span style=\"color: #007700;\">()\u00a0{<br \/>\n<\/span><span style=\"color: #0000bb;\">$label <\/span><span style=\"color: #007700;\">=\u00a0new <\/span><span style=\"color: #0000bb;\">GtkLabel<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;Hello\u00a0World\u00a0&#8211;\u00a0will\u00a0fail&#8221;<\/span><span style=\"color: #0000bb;\">);<br \/>\n$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">add<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">$label<\/span><span style=\"color: #007700;\">);<\/span><\/p>\n<p><span style=\"color: #0000bb;\">$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">show<\/span><span style=\"color: #007700;\">();<br \/>\n<\/span><span style=\"color: #0000bb;\">$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">show_all<\/span><span style=\"color: #007700;\">();<\/span><\/p>\n<p><span style=\"color: #0000bb;\">Gtk<\/span><span style=\"color: #007700;\">::<\/span><span style=\"color: #0000bb;\">main<\/span><span style=\"color: #007700;\">();<\/span><br \/>\n}<br \/>\n}<br \/>\n<span style=\"color: #0000bb;\">$a <\/span><span style=\"color: #007700;\">=\u00a0new <\/span><span style=\"color: #0000bb;\">Myclassw<\/span><span style=\"color: #007700;\">();<br \/>\n<\/span><span style=\"color: #0000bb;\">?&gt;<br \/>\n<\/span>You should receive the following errors: (path may be different)<\/p>\n<ul>\n<li>PHP Fatal error:  Internal object missing in Myclassw wrapper in <em>\/usr\/dev\/php5\/gtk2\/bug.php<\/em> on line 14<\/li>\n<li>Fatal error: Internal object missing in Myclassw wrapper in <em>\/usr\/dev\/php5\/gtk2\/bug.php<\/em> on line 14<\/li>\n<\/ul>\n<p>Now, try this snippet:<br \/>\n<code><span style=\"color: #000000;\"><br \/>\n<span style=\"color: #0000bb;\">&lt;?php<br \/>\n<\/span><span style=\"color: #007700;\">if\u00a0(!<\/span><span style=\"color: #0000bb;\">class_exists<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">'gtk'<\/span><span style=\"color: #007700;\">))\u00a0{<br \/>\ndie(<\/span><span style=\"color: #dd0000;\">\"ERROR:\u00a0No\u00a0PHP-GTK2\u00a0Module.\\n\"<\/span><span style=\"color: #007700;\">);<br \/>\n}<br \/>\nclass <\/span><span style=\"color: #0000bb;\">Myclassw <\/span><span style=\"color: #007700;\">extends <\/span><span style=\"color: #0000bb;\">GtkWindow <\/span><span style=\"color: #007700;\">{<br \/>\nprotected <\/span><span style=\"color: #0000bb;\">$label<\/span><span style=\"color: #007700;\">;<\/span><\/span><\/code><\/p>\n<p>function\u00a0<span style=\"color: #0000bb;\">__construct<\/span><span style=\"color: #007700;\">()\u00a0{<br \/>\n<\/span><span style=\"color: #0000bb;\">parent<\/span><span style=\"color: #007700;\">::<\/span><span style=\"color: #0000bb;\">__construct<\/span><span style=\"color: #007700;\">(); <\/span><span style=\"color: #ff8000;\">\/\/\u00a0New\u00a0line\u00a0inserted\u00a0here<\/span><\/p>\n<p><span style=\"color: #0000bb;\">$label <\/span><span style=\"color: #007700;\">=\u00a0new <\/span><span style=\"color: #0000bb;\">GtkLabel<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #dd0000;\">&#8220;Hello\u00a0World\u00a0&#8211;\u00a0will\u00a0work!&#8221;<\/span><span style=\"color: #007700;\">);<br \/>\n<\/span><span style=\"color: #0000bb;\">$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">add<\/span><span style=\"color: #007700;\">(<\/span><span style=\"color: #0000bb;\">$label<\/span><span style=\"color: #007700;\">);<br \/>\n<\/span><span style=\"color: #0000bb;\">$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">show<\/span><span style=\"color: #007700;\">();<br \/>\n<\/span><span style=\"color: #0000bb;\">$this<\/span><span style=\"color: #007700;\">-&gt;<\/span><span style=\"color: #0000bb;\">show_all<\/span><span style=\"color: #007700;\">();<br \/>\n<\/span><span style=\"color: #0000bb;\">Gtk<\/span><span style=\"color: #007700;\">::<\/span><span style=\"color: #0000bb;\">main<\/span><span style=\"color: #007700;\">();<br \/>\n}<br \/>\n}<br \/>\n<\/span><span style=\"color: #0000bb;\">$a <\/span><span style=\"color: #007700;\">=\u00a0new <\/span><span style=\"color: #0000bb;\">Myclassw<\/span><span style=\"color: #007700;\">();<br \/>\n<\/span><span style=\"color: #0000bb;\">?&gt;<br \/>\n<\/span>Now this time, it should work as expected. If you encounter &#8220;ERROR: No PHP-GTK2 module.&#8221;, this means that you are either running it in your web server or ran it without php-gtk2.(so\/dll) in your php.ini.<\/p>\n<p>All tests were ran on <a rel=\"nofollow\" href=\"http:\/\/www.ubuntu.com\">Ubuntu Linux<\/a> 8.04, PHP 5.2.4-2ubuntu5.3 and Linux kernel version 2.6.24-19-generic. If this article helped you solve the problem, please help us spread the word or please leave a comment. Don&#8217;t forget to <a href=\"\/labs\/feed\/\">subscribe<\/a> to Compdigitec Labs for more interesting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>In PHP-GTK2, if you build your own class of an existing PHP-GTK2 class, you may encounter one of the following errors: &#8220;PHP Fatal error:\u00a0 Internal object missing in YourclassName wrapper in \/path\/to\/your\/script on line *&#8221; &#8220;Fatal error: Internal object missing in YourclassName wrapper in \/path\/to\/your\/script on line *&#8221; This is somehow (not documented) caused by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,5,4],"tags":[76,75,79,78,864,77,11,80,74],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/22"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}