Jump to content

What would you love to see changed or add to PHP?


tibberous

Recommended Posts

Best thing I can think of is letting a mysql result work in a foreach loop.

 

$result = mysql_query("...");

 

foreach($result as $result){

 

}

 

And it would work the same as:

 

while($result = mysql_fetch_array($result)){

 

}

 

Its a minor change but I think it is a really nice one. I'm not 100% sure you can't overload the foreach operator to do it in PHP 5.

 

What would you change if you could?

Link to comment
Share on other sites

mostly i'd want a cleanup job, just so functions follow the same naming conventions (ie, with respect to using underscores in some functions and none in others), have the needle/haystacks all the same way around, etc. it's getting slowly better as we move along but still needs work.

 

all i'd really ask for is that PHP doesnt try to force a particular coding style (ie, OOP vs functional) on people, as half of PHP's charm is its simplicity - whereas the Zend framework and many extensions available are just a tad too complex, IMO.

 

My only other thing would be to allow true legacy support (maybe even using a flag or something in the php.ini file), so that a host can upgrade their PHP version to the latest without worrying about breaking sites - the fact that we're getting nearer to an official version of PHP6, yet some hosts are stuck on PHP4 is not good at all for the language/community/future as a whole - the reason hosts give is that incompatibilities will break too many sites they host. I didnt have too much breakage when I upgraded my own server, but I enough to have cost me money to pay a developer to do it if I couldnt have done it myself.

Link to comment
Share on other sites

Best thing I can think of is letting a mysql result work in a foreach loop.

 

$result = mysql_query("...");

 

foreach($result as $result){

 

}

 

And it would work the same as:

 

while($result = mysql_fetch_array($result)){

 

}

 

Its a minor change but I think it is a really nice one. I'm not 100% sure you can't overload the foreach operator to do it in PHP 5.

 

What would you change if you could?

 

Issue with this is that not all queries are going to arrays or arrays of arrays.  I don't think this is major problem as there are many many many classes the resolve this issue and it is very easy to create your own, i am using my own database class(I think if you are using string up mysql functions, you should be upgrading to a database/mysql class).

 

One thing that i would like to see that was released in the early version of php5 but removed is namespaces, other than that I would also like to see all function name standardized however with the amount of code already of for php, that would take alot of work for people to upgrade if they did that.

Link to comment
Share on other sites

mostly i'd want a cleanup job, just so functions follow the same naming conventions (ie, with respect to using underscores in some functions and none in others), have the needle/haystacks all the same way around, etc. it's getting slowly better as we move along but still needs work.

 

I'd go along with that. It seems somewhat childish that the order of parameters and naming conventions aren't consistant.

 

 

Link to comment
Share on other sites

mostly i'd want a cleanup job, just so functions follow the same naming conventions (ie, with respect to using underscores in some functions and none in others), have the needle/haystacks all the same way around, etc. it's getting slowly better as we move along but still needs work.

I'd go along with that. It seems somewhat childish that the order of parameters and naming conventions aren't consistant.

 

This would be nice but that would require a lot of people to change a lot of code, I don't think this is going to be happening becuse it would break so much code.  This is one of the design flaw of php that is annoying(well really lack of design flaw).

Link to comment
Share on other sites

This would be nice but that would require a lot of people to change a lot of code, I don't think this is going to be happening becuse it would break so much code.  This is one of the design flaw of php that is annoying(well really lack of design flaw).

 

Not necessarily.  In most cases, the needle is a scalar and the haystack is an array.  In that case, you just change the function implementation to check the type of the first and second arguments.  Then you change the documentation to reflect whatever.

 

That should handle 99% of it.

Link to comment
Share on other sites

I'd like to be able to do this:

 

(python)

s = 'PHP Freaks'
print s[:3]

Output: PHP

I believe it's called slicing. I know that substr() can do that, but slicing in Python works on lists as well.

forums = ['SMF', 'phpBB', 'vBulletin', 'IPB']
commercial = forums[2:]
free = forums[:2]

 

I'd also like to be able to do this. It's Python again.

db_settings = {"host":"localhost", "user":"root", "password":"", "dbname":"test"}
print ";".join(["%s=%s" % (k, v) for k, v in db_settings.items() if len(v)>0])

Output: host=localhost;user=root;dbname=test

 

The shortest way I can think of doing that in PHP would be:

<?php
$db_settings = array('host'=>'localhost', 'username'=>'root', 'password'=>'', 'dbname'=>'test');
$pieces = array();
foreach($db_settings as $k => $v)
{
if(!strlen($v)>0) continue;
$pieces[] = "{$k}={$v}";
}
echo join(';', $pieces);
?>

 

Python is really cool

Link to comment
Share on other sites

What would you change if you could?
I would include an efficient opcode cache in it and have it enabled by default so that 3rd party applications aren't needed to make PHP fast.

I would include a function that lets you instantly kill the current PHP process without sending any packets to the client.

I would make sure a 64bit version is officially released on the official PHP website.

I would standardize the function names. So that they are all in the same format. Like have them either all use camelCapsLikeThis or all use underscores_like_this instead of the random mix and match it is now.

I would make the stuff in the functions be in the same order. Like always have the haystack first, or always the needle first, instead it being random like it is now.

 

Pretty much everything else I can think of off the top of my head is already included in PHP 6 :D

 

Edit: oh and I'd add an option to the php.ini to disable all of the error checking, so that scripts that are no longer being developed and don't have any errors in them will be able to run faster since the overhead of checking for all the errors will be gone.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.