php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32584 count() doesnt work in some cases
Submitted: 2005-04-05 10:51 UTC Modified: 2005-04-05 11:35 UTC
From: xsmokex at chello dot at Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.3 OS: Windows 2003 Server
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xsmokex at chello dot at
New email:
PHP Version: OS:

 

 [2005-04-05 10:51 UTC] xsmokex at chello dot at
Description:
------------
count just stops returning any values inside my function
outside it returns the value it should quite dissapointing bug :/

Reproduce code:
---------------
$idxsplit = "kunden___Kunden_Nr,kunden___Zuname";
$idx = explode(",",$idxsplit); //Index Felder
$idxcnt = count($idx);
echo $idxcnt;
//Aktives Feld Index Feld?
function isidx($obj) {
  echo $obj;
  $retval = 0;
  if ($obj != "") {
    echo "obj";
    echo $idxcnt;
    echo "test";
    for ($i = 0; $i < $idxcnt; $i++) {
      echo $idx[$i];
      if ($idx[$i] == $obj) {
        $retval = 1;
        break;
      }
    }
  }
  echo $idxcnt;
  echo "ende".$retval;
  return $retval;
}
//Erster Satz
if ($kunden___speichern == "mer") {
  if (isidx($kunden___AKTFLD)) { //kunden___Kunden_Nr/kunden___Zuname

Expected result:
----------------
well runing isidx() with $kunden___AKTFLD(value:kunden___Kunden_Nr or kunden___Zuname ....)
returning true/false if the current selected field is a indexed field

Actual result:
--------------
the echo returnings:
2kunden___Kunden_Nrobjtestende0 

Broken down:

outside function:

2:               echo $idxcnt;


inside function:

kunden___Kunden: echo $obj;
obj:             echo "obj";
:                echo $idxcnt; //no value returned
test             echo "test";
:                echo $idx[$i]; //dont get into due no value from $idxcnt
:                echo $idxcnt; //no value returned
ende0            echo "ende".$retval;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-05 11:02 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-04-05 11:22 UTC] xsmokex at chello dot at
sorry didnt know u need it for tests in that way here you have the requested sample (no additional things needed just run it)

SCRIPT:

<?php
$idxsplit = "kunden___Kunden_Nr,kunden___Zuname";
$idx = explode(",",$idxsplit); //Index Felder
$idxcnt = count($idx);
echo $idxcnt;
//Aktives Feld Index Feld?
function isidx($obj) {
  echo $obj;
  $retval = 0;
  if ($obj != "") {
    echo "obj";
    echo $idxcnt;
    echo "test";
    for ($i = 0; $i < $idxcnt; $i++) {
      echo $idx[$i];
      if ($idx[$i] == $obj) {
        $retval = 1;
        break;
      }
    }
  }
  echo $idxcnt;
  echo "ende".$retval;
  return $retval;
}
//the Test (should normally return echo "index field";)
if (!isidx("kunden___Kunden_Nr")) {
  //not a indexfield
  echo "not a index field";
}
else {
  echo "index field";
}
?>
 [2005-04-05 11:35 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

No bug here, $idx & $idxcnt are just in the different scope.
Use error_reporting(E_ALL) to turn on notices and read the documentation more carefully.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 18:00:02 2025 UTC