GithubHelp home page GithubHelp logo

Comments (20)

dynasource avatar dynasource commented on May 28, 2024 3

whether there is an abstraction layer between it or not, one expects a count function to return a number, not a string. This is the most intuitive result.

from db.

rob006 avatar rob006 commented on May 28, 2024 1

I would say that we should do it a long time ago. W can safely convert count() result to int, so there is no technical problem here.

from db.

rob006 avatar rob006 commented on May 28, 2024 1

The only con is that we'll have int|string as a type hint :(

Numerical string will be returned only in edge cases (when you need integer bigger than your environment can handle). We could:

  1. Laravel style - f*ck edge cases and always cast to int.
  2. Remove string from typehint - in 99.9999% cases you will get int anyway, so string in typehint may give more harm than good.

@ptz-nerf This is not a code sample. How do you want to use === on comparing result with integer that cannot be represented as integer?

from db.

schmunk42 avatar schmunk42 commented on May 28, 2024 1

I'd also expect an integer here.

From https://stackoverflow.com/questions/670662/whats-the-maximum-size-for-an-int-in-php even on 32bit systems this would be limited to ~2 billion, which is quite large and on 64bit to ~9 quintillion.

from db.

cebe avatar cebe commented on May 28, 2024

This is normal because PDO does always return strings regardless what value it was on DB side. Because PHP is not stricly typed this should not be a problem.

from db.

nenad-zivkovic avatar nenad-zivkovic commented on May 28, 2024

If you are doing strict comparisons of result and some integer value it is. But of course, it is a question do you really need to do strict comparison at all... I guess it is not a "real" problem. Thanks for info.

from db.

cebe avatar cebe commented on May 28, 2024

You should only do strict comparison if you are really sure or really need to. This is not such a case.

from db.

ptz-nerf avatar ptz-nerf commented on May 28, 2024

if you are really sure

When can count() return not integer number? string|int return type is missleading: people expect to see the number, suspecting that string will be return in a rare strange situation. Everything is quite the opposite, int (0) will be return only if emulateExecution is true...

from db.

rob006 avatar rob006 commented on May 28, 2024

#14704

from db.

samdark avatar samdark commented on May 28, 2024

Hmm... yes. We can't do it :(

from db.

samdark avatar samdark commented on May 28, 2024

32bit ints?

from db.

rob006 avatar rob006 commented on May 28, 2024

With approach from #14704 it will be represented as numerical string.

from db.

samdark avatar samdark commented on May 28, 2024

But that's quite inconsistent. It's better to cast to string than to have two types. Developers will use === and will be quite surprised when the project DB would exceed 32bit int.

from db.

rob006 avatar rob006 commented on May 28, 2024

Developers will use === and will be quite surprised when the project DB would exceed 32bit int.

Can you give a code sample, when this will happen? You will get string only if result cannot be converted to integer, so how do you want to use === in this case?

BTW: Developers are already surprised that count() returns string. And such inconsistency already exists in AR.

from db.

ptz-nerf avatar ptz-nerf commented on May 28, 2024

#14704
Indeed, string is better.

from db.

samdark avatar samdark commented on May 28, 2024

Actually what @rob006 proposes makes sense in practice. While under a 100 it may make sense to strictly compare counts, more than several thousands should always be done with > or < and for these operators it doesn't really make any difference if operands are strings or ints.

The only con is that we'll have int|string as a type hint :(

from db.

samdark avatar samdark commented on May 28, 2024

Let's cast to int as @rob006 originally proposed. @yiisoft/core-developers objections?

from db.

ptz-nerf avatar ptz-nerf commented on May 28, 2024

Given that the result can be of different types on any numbers (yiisoft/yii2#14704 (comment)), it is better to have int (with @rob006 check) in most situations. On x64 it is insignificant. string really surprised me at the first moment.

from db.

SilverFire avatar SilverFire commented on May 28, 2024

No objections

from db.

terabytesoftw avatar terabytesoftw commented on May 28, 2024

done.

from db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.