By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Extending the mysqli class

P: n/a
Daz
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.

Feb 25 '07 #1
Share this Question
Share on Google+
21 Replies


P: n/a
Daz wrote:
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.
Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #2

P: n/a
Daz
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.

OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.

Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.

I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.

I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.

I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.

Feb 25 '07 #3

P: n/a
Daz
On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Daz wrote:
Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.

Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks for that Jerry. That gives me something to go on. I am using
PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
most likely wrong).

Thanks again for your assistance.

Daz.

Feb 25 '07 #4

P: n/a
Daz wrote:
On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Daz wrote:
>>Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.
Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


Thanks for that Jerry. That gives me something to go on. I am using
PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
most likely wrong).

Thanks again for your assistance.

Daz.
Daz,

Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)

instead.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #5

P: n/a
Daz wrote:
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
>Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.


OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.

Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.

I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.

I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.

I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.
Daz,

Overriding the constructor is quite common. But you need to ensure you
also call the parent class constructor.

As to seeing the code - it's like anything else in PHP. If it's a PHP
file, you can see the code. If, like with mysqli, it's a compiled
extension, you need to look at the source code for the extension.

If you want some error checking when you open the connection, see if the
connection is open after calling the mysqli constructor (see if
mysqli_connect_error() is non-zero).

You don't need an external function - you just need to check for errors.
And if you don't want to keep checking the responses, check you
exception handling.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #6

P: n/a
Daz
On Feb 25, 4:17 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Daz wrote:
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.
OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.
Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.
I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.
I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.
I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.

Daz,

Overriding the constructor is quite common. But you need to ensure you
also call the parent class constructor.

As to seeing the code - it's like anything else in PHP. If it's a PHP
file, you can see the code. If, like with mysqli, it's a compiled
extension, you need to look at the source code for the extension.

If you want some error checking when you open the connection, see if the
connection is open after calling the mysqli constructor (see if
mysqli_connect_error() is non-zero).

You don't need an external function - you just need to check for errors.
And if you don't want to keep checking the responses, check you
exception handling.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks for that Jerry. You're a star! :)

Feb 25 '07 #7

P: n/a
Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)
Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}
}

output_methods("mysqli");
?>

Feb 25 '07 #8

P: n/a
Actually, PHP4 does support the mysqli object, also.
>
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)
Also just thought of another clarification. If you do not declare a
constructor for a class that extends another class, the parent constructor
will be called. for example the following code snippet will output "parent
constructor and the input was THIS TEXT":-

<?php
class c1
{
function __construct($input)
{
echo "parent constructor and the input was ".$input;
}
}
class c2 extends c1
{
}
$c = new c2('THIS TEXT');
?>
Feb 25 '07 #9

P: n/a
Daz
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>

Excellent! Just what I needed :)

I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique, as there's no guarantee that the server it needs to run on
is running PHP5. Some people have no control over what version of PHP
is installed if they are simply paying for a basic hosting account.
Fortunately for me, I have the choice between 4 and 5, but others
won't necessarilly be quite so fortunate.

Thanks for your help Peter. That's sure going to save me digging
through source code and scratching my head to to point of baldness.

Best wishes.

Daz.

Feb 25 '07 #10

P: n/a
Daz
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>

I have just one more question. Seeing that you can print methods, how
would I print the code from a function?

Many thanks.

Daz.

Feb 25 '07 #11

P: n/a
peter wrote:
>Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.
That's true if there is no __constructor method. However, from what I
understand, the old classname constructor is going away. If you're on
PHP5, you should be using the new way.
The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}
}

output_methods("mysqli");
?>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #12

P: n/a
Daz wrote:
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
>>Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)
Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>


Excellent! Just what I needed :)

I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique, as there's no guarantee that the server it needs to run on
is running PHP5. Some people have no control over what version of PHP
is installed if they are simply paying for a basic hosting account.
Fortunately for me, I have the choice between 4 and 5, but others
won't necessarilly be quite so fortunate.

Thanks for your help Peter. That's sure going to save me digging
through source code and scratching my head to to point of baldness.

Best wishes.

Daz.
Daz,

It was changed because they're moving away from the old classname
constructor to just __constructor. New code on php5 should be using the
new method.

For compatibility with PHP4, just create your constructor as
__constructor. Then create a classname constructor and have it call
__constructor.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #13

P: n/a
..oO(Daz)
>I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique
I don't care about PHP 4 anymore. Personally I consider it dead.
>as there's no guarantee that the server it needs to run on
is running PHP5.
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.

Micha
Feb 25 '07 #14

P: n/a
I havejustone more question. Seeing that you can print methods, how
would I print the code from a function?
As far as I know you cannot print the code for a class method only
retrieve it's name.

(had to use google groups to post a reply as for some some reason my
news provider is not working properly)

Feb 25 '07 #15

P: n/a
I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, wouldjustuse the PHP4 constructor
technique

I don't care aboutPHP4 anymore. Personally I consider it dead.
as there's no guarantee that the server it needs to run on
is running PHP5.

My scripts make use of many of the new OOP features inPHP5, so they
won't run at all onPHP4.

Micha
That is all good and well if you are only coding for yourself but as
the following stats page shows php 4 still has 85% or the market
(although it is decreasing at an ever faster rate)

http://www.nexen.net/chiffres_cles/p...olution.global

Feb 25 '07 #16

P: n/a
..oO(ad***@fahost.com)
>My scripts make use of many of the new OOP features inPHP5, so they
won't run at all onPHP4.

That is all good and well if you are only coding for yourself but as
the following stats page shows php 4 still has 85% or the market
(although it is decreasing at an ever faster rate)
I'm not only coding for myself, but I clearly state that my scripts
require a PHP 5 server and usually I'm the one who decides where to host
a site.

Similarly you can't expect modern software to run on an old system like
Windows 3.1 anymore. And PHP 4 _is_ old. At some point you simply have
to draw the line.

Micha
Feb 26 '07 #17

P: n/a
Michael Fesser wrote:
.oO(Daz)
>I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique

I don't care about PHP 4 anymore. Personally I consider it dead.
>as there's no guarantee that the server it needs to run on
is running PHP5.

My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.

Micha
Micha,

Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you. And PHP 4 is
not past end-of-life yet, according to PHP.NET.

A good consultant takes all this into consideration, also.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 26 '07 #18

P: n/a
..oO(Jerry Stuckle)
>Michael Fesser wrote:
>>
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you.
Sure, but I don't write my scripts for such servers.

I don't know about the situation where you are, but at least here in
Germany offering PHP 5 support is a _must_ for a reputable host.
>And PHP 4 is
not past end-of-life yet, according to PHP.NET.
PHP 6 is going to see the light of day.
>A good consultant takes all this into consideration, also.
A good consultant also knows when it's time for an important upgrade or
a host change. PHP 5 not only has much more features than PHP 4, but is
also faster, more secure and more flexible.

Micha
Feb 26 '07 #19

P: n/a
Michael Fesser wrote:
.oO(Jerry Stuckle)
>Michael Fesser wrote:
>>My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you.

Sure, but I don't write my scripts for such servers.

I don't know about the situation where you are, but at least here in
Germany offering PHP 5 support is a _must_ for a reputable host.
>And PHP 4 is
not past end-of-life yet, according to PHP.NET.

PHP 6 is going to see the light of day.
>A good consultant takes all this into consideration, also.

A good consultant also knows when it's time for an important upgrade or
a host change. PHP 5 not only has much more features than PHP 4, but is
also faster, more secure and more flexible.

Micha
Micha,

No arguments about it being faster, etc. However, the market doesn't
always upgrade to the latest. There are a lot of hosts still running
PHP4, all over the world. And to say you won't program for them means
you're missing an awful lot of customers.

But hey - it's your loss, not mine.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 26 '07 #20

P: n/a
Daz wrote:
I am wondering why constructors are different in PHP5.
Under PHP 4:

<?php
class A
{
function A ()
{
print "Constructor called\n";
}
}

class B extends A
{
// The constructor for this class is now a
// function called 'A'. If you were reading the
// code, this might be somewhat confusing, but
// you could logically infer that it's because
// it extends A.
}

class C extends B
{
// The constructor for this class is now a
// function called 'A'. There is no clue within
// this class definition as to why that is! If
// classes A and B were defined in a separate
// file, then there would be no clues in this
// file that the constructor function is called
// 'A'.
}

class D extends C
{
function D ()
{
print "This is D!\n";
parent::C(); // wrong!
}
}
?>

PHP 5 allows all classes to have the same name for their constructor. So
when subclassing an existing class, you can reliably call the parent's
constructor function as "parent::__contruct()" without having to look into
the internals of the class that you're extending. (Which is how it should
be with OO programming: classes should be black boxes.)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 27 '07 #21

P: n/a
Michael Fesser wrote:
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Ditto.

My current big pet project is http://demiblog.org/. This is PHP 5+ only
and supports MySQL 5+ and PostgreSQL 8+. Although I do realise that earlier
versions of these packages are still quite widely used out there, this
project probably won't hit the big 1.0 for another year or two, by which
time, the hosting world will have probably moved on a lot. Supporting
older versions of PHP and the database engines will cost development time
and push back the project release date even later, by which time PHP 4
support will be even less relevant.

So although PHP 4 may still be alive right now, it's counting down the
days to his retirement when it can hand over the family business to his
son PHP 5. He's heard the happy news that his dranddaughter PHP 6 is
planning on following in their footsteps too as soon as she graduates.
Because of PHP 4's impending retirements, he's not taking on any more big
projects at work, and is letting his son take on most of the new clients.

Analogy over, it would be unwise at this point to look at supporting PHP 4
for any medium-to-large projects that are starting now or in the future.
Existing PHP 4 projects should probably keep supporting PHP 4 for a while
yet, but should certainly make an effort to support PHP 5 as well, and
should be keeping a close eye on PHP 6 developments.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 27 '07 #22

This discussion thread is closed

Replies have been disabled for this discussion.