Re: [PHP-DEV] proc_open() resources and their destruction
Op 12-07-12 19:02, Ángel González schreef: On 12/07/12 17:30, Johannes Schlüter wrote: Hi, On Thu, 2012-07-12 at 17:09 +0200, Jille Timmermans wrote: An implementation is quite simple: https://github.com/Jille/php-src/commit/31a1aa384c29487e077ccf3fd067eca188cf1201 Without looking at the functional change itself a comment: The patch in this form can not be applied to 5.4 as php_file_globals is an exported public structure. If that branch is aimed for it might be acceptable to move int pclose_wait; to the end of the structure there. While even that isn't 100% nice. For 5.3 we certainly shouldn't do a functional change so late in the life cycle. johannes The pclose_wait on php_file_globals isn't needed. If only proc_close() is going to wait on the process, copy proc-childHandle/proc-child, before doing the zend_list_delete() in proc_close and move the waiting code (lines 222-244) of proc_open_rsrc_dtor below that call. Not only you don't need to add a pclose_wait member, you now can get rid of pclose_ret, too. Agreed. What is the policy in this situation? Angels proposed changes are cleaner but they deprecate the pclose_ret field which could be used by third-party extensions. Do we want to commit the same code to 5.4 and 5.5+? Otherwise we could use my patch for 5.4 and Angels proposal for 5.5+? -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] array_shift() and reindexing
Hello, array_shift() currently reindexes the array after shifting one element. The reindexing has quite some impact on it's performance. I would like to suggest an extra parameter to array_shift() which can be used to prevent reindexing. From a few quick (and sloppy!) tests I get these results: `reset($array); list($key, $value) = each($array); unset($array[$key]);` is ~50-150 times faster than array_shift(). Calling array_reverse() and using array_pop() is ~2000-5000 times faster. If you agree this would be an useful addition I will create a patch. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] array_shift() and reindexing
It seems 7-8 times slower than array_shift() and that is even without a way to fetch the first value. I tried `$array = array_slice($array, 1)` and `$array = array_slice($array, 1, NULL, true);` -- Jille Op 12-07-12 14:39, David Muir schreef: What about replacing the existing array with array_slice? David On 12/07/2012, at 9:43 PM, Jille Timmermans ji...@quis.cx wrote: Hello, array_shift() currently reindexes the array after shifting one element. The reindexing has quite some impact on it's performance. I would like to suggest an extra parameter to array_shift() which can be used to prevent reindexing. From a few quick (and sloppy!) tests I get these results: `reset($array); list($key, $value) = each($array); unset($array[$key]);` is ~50-150 times faster than array_shift(). Calling array_reverse() and using array_pop() is ~2000-5000 times faster. If you agree this would be an useful addition I will create a patch. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] array_shift() and reindexing
Op 12-07-12 15:18, Johannes Schlüter schreef: On Thu, 2012-07-12 at 13:43 +0200, Jille Timmermans wrote: Hello, array_shift() currently reindexes the array after shifting one element. The reindexing has quite some impact on it's performance. I would like to suggest an extra parameter to array_shift() which can be used to prevent reindexing. From a few quick (and sloppy!) tests I get these results: `reset($array); list($key, $value) = each($array); unset($array[$key]);` is ~50-150 times faster than array_shift(). Calling array_reverse() and using array_pop() is ~2000-5000 times faster. If you agree this would be an useful addition I will create a patch. I haven't checked this, but is the difference only due to the re-hashing or also due to the fact that that array_shift() is taking the array by reference and therefore making a copy during the call if other cow-references (refcount1, isref=0) exist? If I disable the reindexing code array_shift() becomes ~300 times faster. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] proc_open() resources and their destruction
Hello, When you create process with proc_open() (or popen()) you'll get a process-resource. The destructor of this resource calls waitpid() (or it's Windows-equivalent) and waits for the childprocess to die. I think it is very counter-intuïtive that when you derefence the resource it will wait, possibly forever, for the process to exit. This also makes it hard to start a process which should outlive the current process. To maintain BC and give users a way to wait for the process I think proc_close() should still wait for the process, but in case the resource gets dereferenced I would like to change the behaviour. I doubt anyone is relying on the current behaviour if they don't call proc_close(). An implementation is quite simple: https://github.com/Jille/php-src/commit/31a1aa384c29487e077ccf3fd067eca188cf1201 -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Function boolval()
On 28-04-12 06:27, Kalle Sommer Nielsen wrote: 2012/4/27 Jille Timmermansji...@quis.cx: I suggest we add a function boolval(). It simply converts the given argument to a boolean, like strval(), intval() and floatval(). I already have an implementation ready[1]. Why? * It is missing in the current list of *val()-functions and people expect it to exist. I'd say it is an inconsistency. * It can be used as a callback, which is why a bool-cast does not suffice. Does it really matter nowadays when we got closures anyway: $bools = array_map(range('a', 'z'), function($a){ return((boolean) $a); }); Closures can achieve the same goal but are less readable as Sebastian Krebs already pointed out and still confuses the programmer. Sherif Ramadan wrote: Why is this going to be more beneficial to implement? Is it that you feel readability of the closure is too difficult or that you feel there is a use case that presents further benefits for implementing a boolval function, beyond that of just readability or other subjective preferences? Personally, I would feel something like array_filter(range('a','z')); is way more readable than all of the above and makes a lot more sense to me. That's just an example of course. (And doesn't even do the same thing) Under most circumstances, one does not tend to care about the truth in expression unless it is truth. So the following code is far more practical than the suggestions being made here: if (!array_filter(array(0,false,null,'', array( { /* The array is made up entirely of falsey values */ } else { /* The array is not made up entirely of falsey values */ } I'm not saying the function is useless. I'm just saying PHP already offers more than 1,000 functions through core, alone, and adding just one more function that doesn't seem to offer anything new really isn't sounding like a promising idea to me. We only add to people's confusion more by offering them dozens of choices to accomplish the same thing. We've all heard the arguments of print vs. echo, or X vs Y. There's no practical reason to include this in core being presented hear apart from I like it more... I do agree it isn't perfect to have both casts and conversion functions but we're too late now anyway. They both exist - but the boolval conversion function is missing, which is - I think - even worse than yet another function. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Function boolval()
Hi, I suggest we add a function boolval(). It simply converts the given argument to a boolean, like strval(), intval() and floatval(). I already have an implementation ready[1]. Why? * It is missing in the current list of *val()-functions and people expect it to exist. I'd say it is an inconsistency. * It can be used as a callback, which is why a bool-cast does not suffice. -- Jille [1] https://github.com/php/php-src/pull/60 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Function boolval()
On 27-04-12 22:19, Kris Craig wrote: On Fri, Apr 27, 2012 at 1:14 PM, Jille Timmermans ji...@quis.cx Hi, I suggest we add a function boolval(). It simply converts the given argument to a boolean, like strval(), intval() and floatval(). I already have an implementation ready[1]. Why? * It is missing in the current list of *val()-functions and people expect it to exist. I'd say it is an inconsistency. * It can be used as a callback, which is why a bool-cast does not suffice. -- Jille [1] https://github.com/php/php-__src/pull/60 Do you have wiki access? If so, please post an RFC for this! You'd have my vote. =) I don't. If anyone can give it to me I will post an RFC :) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Remove variable function and method calls
On 07/23/10 20:06, Karoly Negyesi wrote: I want to see strong arguments for not casting NULLs into empty arrays:) All simple types (non object/arrays) getting cast to an array will become array($x) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] In memory support for openssl_pkcs7_*
For the record: I created a proof-of-concept patch which changes openssl_pkcs7_sign() to use the input filename as a string instead as a filename. Paul has tested this and it seems to work. I don't know what the best way is to go from here. We could add an extra argument to all those functions which toggles whether they are threated as filenames or not. Or we could let all the functies also accept streams, etc.. Is there a maintainer of the OpenSSL (pcks7) functions? -- Jille Op 15-7-2010 11:15, Paul van Brouwershaven schreef: Hi, The PHP functions openssl_pkcs7_(sign|encrypt|decrypt|verify) do require files to be executed. In many cases this will create the unintended requirement of temporary files. In compare with openssl_(sign|encrypt|decrypt|verify|...) which are doing almost the same thing this is a strange behavior. When we look at the purpose of openssl_pkcs7_* (working with digital signatures in mail), you would not expect to work with files instead of strings for this few data. Regards, Paul Index: openssl.c === --- openssl.c (revision 14) +++ openssl.c (working copy) @@ -3514,12 +3514,12 @@ uint strindexlen; HashPosition hpos; char * strindex; - char * infilename; int infilename_len; + char * infiledata; int infiledata_len; char * outfilename; int outfilename_len; char * extracertsfilename = NULL; int extracertsfilename_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ssZZa!|ls, - infilename, infilename_len, outfilename, outfilename_len, + infiledata, infiledata_len, outfilename, outfilename_len, zcert, zprivkey, zheaders, flags, extracertsfilename, extracertsfilename_len) == FAILURE) { return; @@ -3546,13 +3546,13 @@ goto clean_exit; } - if (php_openssl_safe_mode_chk(infilename TSRMLS_CC) || php_openssl_safe_mode_chk(outfilename TSRMLS_CC)) { + if (php_openssl_safe_mode_chk(outfilename TSRMLS_CC)) { goto clean_exit; } - infile = BIO_new_file(infilename, r); + infile = BIO_new_mem_buf(infiledata, infiledata_len); if (infile == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, error opening input file %s!, infilename); + php_error_docref(NULL TSRMLS_CC, E_WARNING, error opening memory input!); goto clean_exit; } -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] #45351: Exception::getTrace() should return 'object' array-element
http://bugs.php.net/45351 I have attached a patch to the feature request. IIRC I should just ask here whether someone is willing to commit it. So, anyone willing to help me? :) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] #45351: Exception::getTrace() should return 'object' array-element
Hello Kalle, First of all, thanks for yor feedback! Kalle Sommer Nielsen schreef: Hello Jille 2010/6/13 Jille Timmermans ji...@quis.cx: http://bugs.php.net/45351 I have attached a patch to the feature request. IIRC I should just ask here whether someone is willing to commit it. So, anyone willing to help me? :) The patch is incorrect (according to what the user requests, and for consistency with debug_backtrace()). What the patch should do is to: 1) Add a new parameter to the arginfo, so reflection can pick this new parameter up, named provide_object I succeeded with that part. 2) Alter the implementation of Exception::getTrace(), ::getTraceAsString() and possibly also ::__toString() so it sends to the proper parameters to the function that builds the trace array/string The trace is generated at the construction of the exception; because we don't know whether getTrace() will get called with provide_object we need to save it anyway. I have tried to alter ::getTrace() to remove the 'object' key from the stack frames if provide_object was given as false. Unfortunately I didn't succeed there. (I don't know much of the internals; and after playing around calling 'random' functies I decided the patch I would create wouldn't be perfect anyway.) So I trashed the parts I was uncertain of and built the following diff: http://junk.quis.cx/XlUKZqbe/zend_exceptions.diff If someone has time and is willing to finish the patch, please go for it. (Or instructing me how to do it; but I assume that will take more time.) -- Jille If you simply change the 0 to 1, then it will be forced every time, and without looking closer to the implementation i can imagine it could cause some unwanted overheat if its not used, or lookup time. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Closure local return
Are you serious? Op 3-5-2010 15:01, mathieu.suen schreef: Hi, The statement 'return' in a closure is now returning from the scope that evaluate the closure (evaluation scope). It could have been in an other way. It could mean return from the scope were the closure is create (define scope). May be it could be interesting to have a syntax for returning from the define scope. For example. $findedElment = $myList-selectIfAbsent($fooo, function(){ return 'No item founded'; //Retrun from the define scope }) //Do somthing with $findedElment So I am asking if there has been some discussion on it or if it could be added? Thanks --Mathieu Suen -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] One suggestion to PHP-FPM
Op 26-4-2010 13:18, Jérôme Loyet schreef: Le 26 avril 2010 13:12, Antony Dovgalt...@daylessday.org a écrit : On 26.04.2010 14:08, Jérôme Loyet wrote: What exactly are you going to do? Killing a process is as easy as exit(), no interfacing is needed. and when threads are used ? You'll kill all threads at once without waiting them to finish what they're doing at the time ? Let's start from the beginning. How are you going to detect how much memory a thread consumes? no ideas It doesn't matter: Memory is process based; so if the process takes too much memory; the process should die. But the SAPI should handle the actual killing of the process; as the SAPI is the only one who knows how much (if any) other threads are still running (correct me if I'm wrong). So, how about moving the calculation code from pecl/memtrack to PHP-core and let both FPM and memtrack use that code? memtrack could do the usual trick; stopping the current script or whatever. and FPM could flag the process as 'over the memory limit' and can kill it as soon as there are no other threads running in that process. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] One suggestion to PHP-FPM
Op 26-4-2010 16:05, Antony Dovgal schreef: On 26.04.2010 18:02, Jille Timmermans wrote: memtrack could do the usual trick; stopping the current script or whatever. and FPM could flag the process as 'over the memory limit' and can kill it as soon as there are no other threads running in that process. There are no threads in FPM or FastCGI. So, there is no problem for them. Let it use memtrack's calculation code and let the SAPI handle as appropriate: killing the process. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] php and multithreading (additional arguments)
Op 2-4-2010 7:16, Andi Gutmans schreef I think that if we were ever to implement threading we would be best off to enable spawning worker threads that have their own context with no shared data (and therefore no requirement for locking). We could then have a message passing API between the threads. Advantages: - Real multi-threading. - Simple straightforward approach which doesn't require a comp. sci. degree to use correctly. - Very stable implementation. That sounds like I want threading; because it sounds cool!. What are the advantages of this above multi-process? The systemcall-overhead for message passing? And why did nobody mention Aprils Fools yesterday; when the request-for-threading was sent ;) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded
Op 22-3-2010 16:14, Johannes Schlüter schreef: On Mon, 2010-03-22 at 15:51 +0100, troels knak-nielsen wrote: We log all errors that happens in our production environment, but as fatal errors can't be handled from within php, we end up with little information to go on for further debugging. I'm not very familiar with the php internals code, but I managed to throw in a hack that appears to work. In the handler function for timeouts (zend_timeout), I raise a WARNING, sleep for 1 second and then resume normal behavior, which results in a fatal error. This gives userland code 1 second to log the error somewhere, which should be sufficient for debugging. A one second delay is no option there. And what actually happens is that the warning triggers your custom error handler. After that it sleeps then it dies. This also creates a nice way to extend the script runtime after the timeout occurred. aka. making the timeout useless for many scenarios it was meant for. This could be made configurable. Shared hosting providers probably want to disable the 'overriding' of the timeout. At my work; all code is written by our own developers; so there's no evil in there ;) (And it would be usefull to give extra debugging information) -- Jille johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded
Op 22-3-2010 17:14, Sufficool, Stanley schreef: -Original Message- From: Jille Timmermans [mailto:ji...@quis.cx] Sent: Monday, March 22, 2010 8:44 AM To: Johannes Schlüter Cc: troels knak-nielsen; PHP Developers Mailing List Subject: Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded Op 22-3-2010 16:14, Johannes Schlüter schreef: On Mon, 2010-03-22 at 15:51 +0100, troels knak-nielsen wrote: We log all errors that happens in our production environment, but as fatal errors can't be handled from within php, we end up with little information to go on for further debugging. I'm not very familiar with the php internals code, but I managed to throw in a hack that appears to work. In the handler function for timeouts (zend_timeout), I raise a WARNING, sleep for 1 second and then resume normal behavior, which results in a fatal error. This gives userland code 1 second to log the error somewhere, which should be sufficient for debugging. A one second delay is no option there. And what actually happens is that the warning triggers your custom error handler. After that it sleeps then it dies. This also creates a nice way to extend the script runtime after the timeout occurred. aka. making the timeout useless for many scenarios it was meant for. This could be made configurable. Shared hosting providers probably want to disable the 'overriding' of the timeout. At my work; all code is written by our own developers; so there's no evil in there ;) (And it would be usefull to give extra debugging information) Think outside the engine. The engine dies with a fatal error, set a handler to run another PHP instance. The engine then passes the error object as serialized argv to the handler. set_fatal_handler(fatal_handler.php); I don't a practical way to continue script execution in any way without causing some issue. The service provider should be able to kill this with a custom error handler set in INI. fatal_handler=mail_fatal.sh #Log / mail using our script fatal_handler= # (default) - Don't allow user override #fatal_handler= # handler undefined / Allow override You can already do that from the shutdown functions. They run even after fatal errors. php -r 'register_shutdown_function(function() { echo bye; }); ohcrap();' But the most common request is a backtrace; which can not be generated from the shutdown function; neither from an external script. (Hey! We could use coredumps for this! That allows post-mortem examination by some external error handler!) -- Jille -- Jille johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded
Op 22-3-2010 17:51, Sufficool, Stanley schreef: -Original Message- From: Jille Timmermans [mailto:ji...@quis.cx] Sent: Monday, March 22, 2010 9:30 AM To: Sufficool, Stanley Cc: 'PHP Developers Mailing List' Subject: Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded Op 22-3-2010 17:14, Sufficool, Stanley schreef: -Original Message- From: Jille Timmermans [mailto:ji...@quis.cx] Sent: Monday, March 22, 2010 8:44 AM To: Johannes Schlüter Cc: troels knak-nielsen; PHP Developers Mailing List Subject: Re: [PHP-DEV] [PATCH] Raise warning first on Maximum execution time exceeded Op 22-3-2010 16:14, Johannes Schlüter schreef: On Mon, 2010-03-22 at 15:51 +0100, troels knak-nielsen wrote: We log all errors that happens in our production environment, but as fatal errors can't be handled from within php, we end up with little information to go on for further debugging. I'm not very familiar with the php internals code, but I managed to throw in a hack that appears to work. In the handler function for timeouts (zend_timeout), I raise a WARNING, sleep for 1 second and then resume normal behavior, which results in a fatal error. This gives userland code 1 second to log the error somewhere, which should be sufficient for debugging. A one second delay is no option there. And what actually happens is that the warning triggers your custom error handler. After that it sleeps then it dies. This also creates a nice way to extend the script runtime after the timeout occurred. aka. making the timeout useless for many scenarios it was meant for. This could be made configurable. Shared hosting providers probably want to disable the 'overriding' of the timeout. At my work; all code is written by our own developers; so there's no evil in there ;) (And it would be usefull to give extra debugging information) Think outside the engine. The engine dies with a fatal error, set a handler to run another PHP instance. The engine then passes the error object as serialized argv to the handler. set_fatal_handler(fatal_handler.php); I don't a practical way to continue script execution in any way without causing some issue. The service provider should be able to kill this with a custom error handler set in INI. fatal_handler=mail_fatal.sh #Log / mail using our script fatal_handler= # (default) - Don't allow user override #fatal_handler= # handler undefined / Allow override You can already do that from the shutdown functions. They run even after fatal errors. php -r 'register_shutdown_function(function() { echo bye; }); ohcrap();' But the most common request is a backtrace; which can not be generated from the shutdown function; neither from an external script. (Hey! We could use coredumps for this! That allows post-mortem examination by some external error handler!) But with register_shutdown_function you do not have an error context right? If the user is doing something with the error, they will need the file, line, message, etc... error_get_last(); Also does register_shutdown_function work with max_execution_time, out of memory, compile error, etc...? I'm really thinking that for a complete fatal handler function to work, it needs to execute a known good handler script outside of the offending code. I agree; but I was trying to point out that it doesn't need to be an external handler. As far as coredumps: Security, where would the file be located? Who on the server would be able to read it? It was a joke ;) -- Jille -- Jille -- Jille johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Inconsistency redesign
var_dump((array)); Results in: array(1) { [0]= string(0) } And 'array()' is not empty. -- Jille Op 13-1-2010 14:50, Etienne Kneuss schreef: Hello, On Wed, Jan 13, 2010 at 2:36 PM, mathieu.suen mathieu.s...@easyflirt.com wrote: Hi, I came across this: echo sizeof(array()); echo sizeof(); $a = ; php.net/count: If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned. var_dump( empty($a)); $a = array(); var_dump(empty($a)); php.net/empty empty($var) is basically an !isset($var) || !$var it's not related to count in anyway. So funny! How something can have a size greater than 0 but still be empty? I think PHP is reinventing the inconsistency word. I think such comments are pretty useless. Try coming with a viable solution as a patch instead. But then let assume that empty is just making a cast in array. If you assume wrong, you can derive all kind of madness. $a = ; empty($a) //true empty((array)$a) //false Ok so empty is big ugly switch case on type. No, it's a boolean check, with type juggling involed, see above. empty(0); //true empty(45); //false Wooow reinventing emptiness on number -- Mathieu Suen -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] is_array on objects with ArrayAccess or Iterator implementations
Op 28-12-2009 17:30, Clint Priest schreef: Has there been any discussion or decision about whether is_array() should return true for objects which implement ArrayAccess or is there another function already available which checks for either being the case? How about $x instanceOf ArrayAccess ? -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] is_a() versus instanceof
Johannes Schlüter schreef: On Sat, 2009-12-19 at 01:42 +0100, Johannes Mueller wrote: if($foo instanceof bar){ .. } // runs without any notification instanceof is a language construct expecting a class identifier. It doesn't complain about on-existing classes as it would need to trigger the __autoloader which might be way too much. Wouldn't it be an idea to make a setting for this ? I find it very annoying (however understandable) it doesn't complain if I make a typo.. I assume this works the same as try-catch(Exceptio $e); (note the missing 'n'); which got me fooled before. (To be sure to be understood: Create a setting which does check the class-existance; even when autoloading must be called for it) -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] bug when using foreach with references?
Richard K Miller schreef: Is this a bug in PHP? No ?php $items = array('apple', 'banana', 'carrot'); print_r($items); foreach ($items as $item) { } $item is now a reference to the last element of $items. print_r($items); foreach ($items as $item) { } And here, the foreach loop writes to $item for each element: thus assiging that value to the last element of $items. print_r($items); ? // Output: Array ( [0] = apple [1] = banana [2] = carrot ) Array ( [0] = apple [1] = banana [2] = carrot ) Array ( [0] = apple [1] = banana [2] = banana ) Two bananas in the last set?! Not what I expected. You can fix your bug by using 'unset($item);' after the second foreach-loop. -- Jille Richard -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php