Re: [PHP] Classes and access to outside variables

2007-10-01 Thread Nathan Nobbe
On 10/1/07, Merlin [EMAIL PROTECTED] wrote: Hello everybody, thank you for all your answers. I am sorry but I just realized that there is an huge difference between PHP5 and PHP4 considering OOP. Unfortunatelly I am still running PHP4.x and cant change this over night. However I still need

Re: [PHP] Classes and access to outside variables

2007-09-30 Thread Martin Alterisio
That's incorrectly syntactically. Won't run. Ok, let's write some code to show how this can be done: class SearchHelper extends AjaxACApplication { private $dbh; public function __construct() { $this-dbh = $GLOBALS['dbh']; } } Better yet, pass the database host in the

[PHP] Classes and access to outside variables

2007-09-29 Thread Merlin
Hi there, I am new to PHP classes and I do want to access a variable outside the class, but somehow that does not work. global also does not have any effect. In the following example I would like to be able to access $dbh from inside the class like I did in that example. This does not work.

Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Martin Alterisio
Refer to the global on the constructor. Anyway, using a global like that is not a good practice. Just pass the variable to the constructor. 2007/9/29, Merlin [EMAIL PROTECTED]: Hi there, I am new to PHP classes and I do want to access a variable outside the class, but somehow that does not

Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Nathan Nobbe
Merlin, if you are using php5 the var keyword is no longer valid; that was used in classes in php4. if you want to structure your classes properly you need to study PPP (public, private, protected) access modifiers. typically member variables are declared to be private or protected, if there will

Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Nathan Nobbe
On 9/30/07, 潘志彬 [EMAIL PROTECTED] wrote: $dbh = 'test'; class search_helper extends AjaxACApplication { /** * Database connection details */ // announce global variable before use it global $dbh; $db_hostname = $dbh; global

Re: [PHP] Classes and access to outside variables

2007-09-29 Thread 潘志彬
$dbh = 'test'; class search_helper extends AjaxACApplication { /** * Database connection details */ // announce global variable before use it global $dbh; $db_hostname = $dbh; ... Regards, Ryu 2007/9/29, Merlin [EMAIL PROTECTED]: