Doc #62788 [Com]: newt example error. (easy 1-line fix)
| From: | kevdevsandom at yahoo dot co dot uk | Date: | Sat, 11 Aug 2012 12:35:03 +0000 |
| Subject: | Doc #62788 [Com]: newt example error. (easy 1-line fix) | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8729@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62788&edit=1
ID: 62788
Comment by: kevdevsandom at yahoo dot co dot uk
Reported by: kevdevsandom at yahoo dot co dot uk
Summary: newt example error. (easy 1-line fix)
Status: Not a bug
Type: Documentation Problem
Package: newt
Operating System: NA
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Hi Aharvey,
Thanks for your response. I believe you are quite right about the call time pass by reference being
removed. A better way to solve it would be:
$rows=null;
$cols=null;
newt_get_screen_size ($rows, $cols);
"and you can pass uninitialised variables into functions expecting arguments by
references"
This is not true. Maybe it's enabled in the default configuration provided with the source
download, but I haven't seen any packaged version of PHP configured this way since the early
2000s. It's poor programming practise and no competent sysadmin would allow it to be put on to
a production server since it leads to buggy code.
Just to re-iterate this point:
PHP Notice: Undefined variable: rows in
/home/ksandom/files/develop/mass-notready/experimentation/newt/newtExample.php on line 13
PHP Notice: Undefined variable: cols in
/home/ksandom/files/develâââââââânotready/experimentation/newt/newtExample.php
on line 13
Previous Comments:
------------------------------------------------------------------------
[2012-08-10 06:33:12] aharvey@php.net
It's fine the way it is: call time pass by reference has been removed in PHP 5.4, and you can
pass uninitialised variables into functions expecting arguments by references.
------------------------------------------------------------------------
[2012-08-09 20:04:20] kevdevsandom at yahoo dot co dot uk
Description:
------------
---
From manual page: http://www.php.net/newt.examples-usage
---
Line 13 needs to be:
newt_get_screen_size (&$rows, &$cols);
Instead of:
newt_get_screen_size ($rows, $cols);
More info:
This is because those variables aren't created until that point, so without the anpersands
it's trying to reference rather than create them and you get this:
PHP Notice: Undefined variable: rows in
/home/ksandom/files/develop/mass-notready/experimentation/newt/newtExample.php on line 13
PHP Notice: Undefined variable: cols in
/home/ksandom/files/develâââââââânotready/experimentation/newt/newtExample.php
on line 13
The complete code that works for me is included in the test script section.
Test script:
---------------
<?php
newt_init ();
newt_cls ();
newt_draw_root_text (0, 0, "Test Mode Setup Utility 1.12");
newt_push_help_line (null);
newt_draw_root_text (-30, 0, "(c) 1999-2002 RedHat, Inc");
newt_get_screen_size (&$rows, &$cols);
newt_open_window ($rows/2-17, $cols/2-10, 34, 17, "Choose a Tool");
$form = newt_form ();
$list = newt_listbox (3, 2, 10);
foreach (array (
"Authentication configuration",
"Firewall configuration",
"Mouse configuration",
"Network configuration",
"Printer configuration",
"System services") as $l_item)
{
newt_listbox_add_entry ($list, $l_item, $l_item);
}
$b1 = newt_button (5, 12, "Run Tool");
$b2 = newt_button (21, 12, "Quit");
newt_form_add_component ($form, $list);
newt_form_add_components ($form, array($b1, $b2));
newt_refresh ();
newt_run_form ($form);
newt_pop_window ();
newt_pop_help_line ();
newt_finished ();
newt_form_destroy ($form);
?>
Expected result:
----------------
Nice text interface.
Actual result:
--------------
These errors spawled over the interface, and only the quit button shows:
PHP Notice: Undefined variable: rows in
/home/ksandom/files/develop/mass-notready/experimentation/newt/newtExample.php on line 13
PHP Notice: Undefined variable: cols in
/home/ksandom/files/develâââââââânotready/experimentation/newt/newtExample.php
on line 13
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62788&edit=1