Bug #49625 [Com]: spl_autoload and case sensitivity

2012-06-15 Thread jdornan at stanford dot edu
Edit report at https://bugs.php.net/bug.php?id=49625&edit=1

 ID: 49625
 Comment by: jdornan at stanford dot edu
 Reported by:jo at feuersee dot de
 Summary:spl_autoload and case sensitivity
 Status: Not a bug
 Type:   Bug
 Package:SPL related
 Operating System:   Linux
 PHP Version:5.3.0
 Block user comment: N
 Private report: N

 New Comment:

This seems like a 20 min fix to me, and I've never looked the sql_autoload code 
before. I spent a good deal of time spinning my wheels on this. I don't see why 
anyone should lose time of this very obvious bug. However it's better to patch 
that to bitch, as I always say. I'll submit my patch and see what happens. It's 
not big deal if this is not fixed, since it's so easy to fix I can keep fixing 
it with each release.

Here is a diff, I'll submit the patch with the "Add a Patch" link.


225d224
<   char *lc_class_file;
227d225
<   int lc_class_file_len;
229d226
<   int mixed_case = 0;
235,236c232
<   lc_class_file_len = spprintf(&lc_class_file, 0, "%s%s", lc_name, 
file_extension);
<   class_file_len = spprintf(&class_file, 0, "%s%s", class_name, 
file_extension);
---
>   class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, 
file_extension);
252,261c248
<   mixed_case = 1;
<   }
< 
< /* fall back to lowercase file name. should issue deprecated warning. 
*/
< if (ret != SUCCESS) {
<   ret = php_stream_open_for_zend_ex(lc_class_file, &file_handle, 
ENFORCE_SAFE_MODE|USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
< }
< 
<   if (ret == SUCCESS) {
<   if (!file_handle.opened_path && mixed_case == 1) {
---
>   if (!file_handle.opened_path) {
263,264d249
<   } else if(!file_handle.opened_path && mixed_case == 0) {
<   file_handle.opened_path = estrndup(lc_class_file, 
lc_class_file_len);
290d274
<   efree(lc_class_file);
295d278
<   efree(lc_class_file);
331d313
< 

PS: I really hate this bug with a passion.


Previous Comments:

[2012-06-01 23:10:39] mrex at interport dot net

After having lost 2 days over this, I agree, this should be fixed.  At the very 
least, it should be documented that spl_autoload lower cases filenames.  I 
spent hours trying to register an autoload class that would fix this, but in 
vain.  How can I know that "dataloader" should be mapped to "DataLoader"?

If it had been documented that filenames were lowercased, I would not have 
spent hours banging my head against a brick wall...


[2012-05-14 23:45:55] david at panmedia dot co dot nz

Please fix this


[2011-09-05 01:32:08] blake dot soley at gmail dot com

I agree, this bug is not bogus.  In fact, it's actually quite serious.  Just 
because spl_autoload was designed poorly doesn't mean it has to remain broken.  
Several fixes have been proposed, please consider implementing one of them to 
make this function cross-platform, and therefore useful.


[2011-08-10 01:13:40] bram048 at gmail dot com

I agree with Simon. There is absolutely no reason not to fix this, while 
keeping 
backwards compatibility.

Two years ago the reason for not fixing it was "breaking BC is not an option". 
There are plenty of alternatives, and to be honest, PHP has broken BC alot of 
times in the last few versions (which is a good thing in my opinion, as long as 
the language becomes cleaner/stricter).

Having all the files in lowercase makes them alot harder to read. Having a 
custom autoloader function is slower and more complicated to get right, and 
just 
makes code more ugly and harder to understand.

At the very least case sensitivity of the SPL autoloader should be 
configurable, 
or available by the use of an extra suffix. I would love to see this in the new 
5.4 release; shouldn't take more than a few lines of code.


[2011-03-08 13:08:42] simon at systemparadox dot co dot uk

Why is this bug marked as bogus?
Even if spl_autoload itself isn't fixed, at the very least a version that does 
it correctly could be added (although in this case it seriously could just be 
fixed by trying the correct case first).

Implementing one in PHP is all very well, but that means that it's non-standard 
and likely incompatible with what each programmer might expect. It's also 
slo

#49125 [NEW]: Error in dba_exists C code

2009-07-31 Thread jdornan at stanford dot edu
From: jdornan at stanford dot edu
Operating system: All
PHP version:  5.2.10
PHP Bug Type: DBM/DBA related
Bug description:  Error in dba_exists C code

Description:

Using dba_exists with a file opened with dba_popen and the db4 handler
will result in an error.

Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT
data

I found a similar problem was reported before for dba_fetch. Since
dba_fetch and dba_exists share common code it was clear to see how this
error could be fixed. Here is a simple diff between the original file and
the fixed version.

*** dba_db4.c 2009-07-31 13:24:14.0 -0400
--- dba_db4.c.fixed 2009-07-31 13:27:49.0 -0400
***
*** 175,181 
--- 175,187 
  DB4_GKEY;
  
  memset(&gval, 0, sizeof(gval));
+ if (info->flags & DBA_PERSISTENT) {
+ gval.flags |= DB_DBT_MALLOC;
+ }
  if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) {
+ if (info->flags & DBA_PERSISTENT) {
+ free(gval.data);
+ }
  return SUCCESS;
  }
  return FAILURE;

I checked an the error still exists in the 5.2 snapshot.


Reproduce code:
---
Test #1



Test #2




Expected result:

Yes, we have b0rk!

Actual result:
--
Test #1

Nothing.

Test #2

Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT
data in /tmp/test2.php on line 8

-- 
Edit bug report at http://bugs.php.net/?id=49125&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49125&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49125&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49125&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49125&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49125&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49125&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=49125&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=49125&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=49125&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=49125&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=49125&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=49125&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=49125&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49125&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=49125&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=49125&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=49125&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=49125&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=49125&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=49125&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=49125&r=mysqlcfg