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 sti
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 cons
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;
$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]>:
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
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 doe
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. C
7 matches
Mail list logo