Doc #62788 [Opn->Nab]: newt example error. (easy 1-line fix)

From: Date: Fri, 10 Aug 2012 06:33:12 +0000
Subject: Doc #62788 [Opn->Nab]: newt example error. (easy 1-line fix)
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8721@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 Updated by: aharvey@php.net Reported by: kevdevsandom at yahoo dot co dot uk Summary: newt example error. (easy 1-line fix) -Status: Open +Status: Not a bug Type: Documentation Problem Package: newt Operating System: NA PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#8721) next »