Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:30:50+00:00 2026-06-04T21:30:50+00:00

If you do empty() on an array with no elements in it, you get

  • 0

If you do empty() on an array with no elements in it, you get true. However, if you do empty() on a Countable object with a count of 0 then you get false. It seems to me a 0 count Countable should be considered empty. Am I missing something?

<?php

class Test implements Countable
{
    public $count = 0;

    public function count ()
    {
        return intval (abs ($this -> count));
    }
}

$test = new Test ();

var_dump (empty ($test));
var_dump (count ($test));

$test -> count = 10;

var_dump (empty ($test));
var_dump (count ($test));

I would have expected the first call to empty to return true, but it doesn’t.

Is there a reasonable reason for this to be the case, or is it a bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:30:51+00:00Added an answer on June 4, 2026 at 9:30 pm

    From the docs:

    Returns FALSE if var has a non-empty and non-zero value.
    
    The following things are considered to be empty:
    
    * "" (an empty string)
    * 0 (0 as an integer)
    * 0.0 (0 as a float)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)
    

    I think $test in your case is still considered an Object, which is not in the list of what empty would return as TRUE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to eliminate empty elements within my String array. This is what I
I've got this form element: $form->input('ChecklistResponseGovernmentInfo.driversLicenseIsOnline', array('type'=>'radio', 'empty'=> true, 'options'=>array(0 => 'No', 1 =>
I want my script to define an empty array. array values should be added
I have an array thats generated dynamically and it has some empty elements. How
In VB6 it is possible to prepand array identifiers with an empty array index.
How to trim a PHP array and remove all empty indexes Array ( [0]
I'm trying to use empty() in array mapping in php. I'm getting errors that
Is there any function available in PHP to check whether an array is empty
Have an array of chars like char members[255]. How can I empty it completely
I writte this code to send multiple attachments: $tablica_plikow=$_FILES[file]; //array of files if(!empty($tablica_plikow['name'])){///if attachment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.