[PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread David Grudl
PHP lacks two very basic functions for working with arrays: - array_first() returning the first element of an array (or null) - array_last() returning the last element of the array (or null) While PHP has functions that return the first and last keys, array_key_first() and array_key_last(), it do

[PHP-DEV] Better name for method Randomizer::nextFloat()

2023-10-14 Thread David Grudl
I would like to suggest changing the name or removing the nextFloat() method, which is coming to PHP 8.3. The Random\Randomizer class will have two new methods for generating random numbers: - getFloat($min, $max [, $boundary]) - nextFloat() Now please try to guess what these methods do and, more

[PHP-DEV] Better name for method Randomizer::nextFloat()

2023-10-14 Thread David Grudl
I would like to suggest changing the name or removing the nextFloat() method, which is coming to PHP 8.3. The Random\Randomizer class will have two new methods for generating random numbers: - getFloat($min, $max [, $boundary]) - nextFloat() Now please try to guess what these methods do and, more

[PHP-DEV] Enhanced __CLASS__ constant

2009-01-21 Thread David Grudl
h magic contant: $obj = factory(MyClass::__CLASS__); // returns object Foo\MyClass, very understandable :-) $obj = factory(Bar::__CLASS__); // returns object Other\Bar, as use statement declares :-) David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] PF 2009

2008-12-31 Thread David Grudl
PF 2009 for PHP internals! And good luck in finishing the PHP 5.3. David G. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] Tip for 5.3: exceptions in __toString and __autoload

2008-12-25 Thread David Grudl
exceptions. Excellent feature of PHP 5.3 would be to resolve this errors. David Grudl

Re: [PHP-DEV] Ternary operator optimization tip

2008-12-14 Thread David Grudl
need to be optimized. The only time you can really tell its slower is in synthetic benchmarks. Few hundred operations involving ternary operator is nothing unusual ;) Původní zpráva Od: Alexey Zakhlestin On Sun, Dec 14, 2008 at 8:06 PM, David Grudl wrote: Do you have any

Re: [PHP-DEV] Removing basic types from our JSON parser

2008-12-14 Thread David Grudl
f apps. +1 In PHP there is no function for escaping JS strings and json_encode is useful compensation. I use it this way very often. David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] Ternary operator optimization tip

2008-12-14 Thread David Grudl
don't know how difficult it is to implement, but it can be very useful speed optimization for PHP 5.3 to improve ternary operator to use reference counting. David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] New namespace implementation

2008-12-02 Thread David Grudl
Snapshot 5.3.0alpha3-dev acts like manual, I think the manual is correct. BTW - this is very useful feature. A "wrong-relative-resolving" rescuer ;) DG. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] New namespace implementation

2008-12-02 Thread David Grudl
Hi! but it generates Warning: The use statement with non-compound name 'ArrayObject' has no effect. The warning is correct. It is not correct - the use statement has effect, as documented in manual http://php.net/manual/en/language.namespaces.importing.php. DG. -- PHP Internals - PHP Runt

[PHP-DEV] New namespace implementation

2008-12-02 Thread David Grudl
ive when it is needed - using 'namespace' operator (as equivalent of the 'self' operator). So I think now there is no reason to use default relative resolving and it should be removed. What about voting? David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Re: Namespace resolution rules has been changed

2008-11-17 Thread David Grudl
I have downloaded last Mono source code (http://www.mono-project.com/, version 2.0.1), the open source version of one of the most complex and mature framework in the world, the .NET framework. Framework is written using namespaces (as opposite to current version of Zend). And I have analysed s

Re: [PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-17 Thread David Grudl
> > Why? I have developed framework using PHP namespaces and studied Zend > > Framework source codes and result is: if we use the new resolution rules > > (1), than in nearly all cases developers must prefix class names with \, > > only in few cases prefix is not required. Why? Because usually

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-17 Thread David Grudl
'\\' . $class; } return new $class; } OMG David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-17 Thread David Grudl
true, however i have a counter example: classes from more general namespace that use further nested classes (think some kind of behaviour and different drivers/plugins for example). so while it's true that more nested classes usually extend the less nested ones it also common for more generic

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-14 Thread David Grudl
let's look at this code: There are a few things to keep in mind. PHP has __autoload(), which C# does not have. Thus, a solution such as: 1) try foo\classes\foo\stuff 2) try foo\stuff Greg, this is clear. I am trying to point something different - to try ONLY 2) and never try 1). Why

[PHP-DEV] New SPL exceptions proposal

2008-11-11 Thread David Grudl
fails. */ class MemberAccessException extends LogicException {} David Grudl -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-11 Thread David Grudl
Původní zpráva Předmět: Re:Namespace resolution rules has been changed? Od: David Grudl <[EMAIL PROTECTED]> Datum: 10.11.2008 23:53 > Can you please point us to an example describing this best practice? For example Namespace Naming Guidelines in .N

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-10 Thread David Grudl
r namespace implementation does, and not like "relative path". David Grudl

[PHP-DEV] Re: Namespace resolution rules has been changed?

2008-11-10 Thread David Grudl
artially qualified indentifiers" (Sub\Object) have to be written with preceding backslash. David Grudl My english is poor but I hope you understand me ;) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] RE:

2008-10-27 Thread David Grudl
. There would have been anything that could have changed this without creating any sort of BC issues. From the possible namespace separators, \ was the best one as we could see. That's how it is, that's I will be glad for each separator, but :: is the best one :-)) David Grudl -- PHP

[PHP-DEV] Re:

2008-10-25 Thread David Grudl
I hope it is only very bad joke :-( namespace myNamespace; class theLoader { function load($class) { ... } } // somewhere else spl_autoload_register(array("myNamespace\theLoader", "load")); -> registers myNamespaceheLoader::load() David Grudl Původní

[PHP-DEV] Re: array_key_exists BC break

2008-10-24 Thread David Grudl
exists($a['item']) -> TRUE // ArrayObject $o = new ArrayObject($a); isset($o['item']) -> TRUE (!) $o->offsetExists($o['item']) -> TRUE (!), in PHP 5.2.1 FALSE (!) Should one rely on this 'isset' behaviour, i.e. will isset($a['item']) return TRU