Welcome Guest, Not a member yet? Register   Sign In
count_all_results returns a string?
#11

[eluser]Thorpe Obazee[/eluser]
I have no intention to being a sarky smartass but I haven't really had any problem with the function returning string. I have always checked for anything functions(I type cast too) return and may have resolved any potential problem with it. I didn't even know count_all_results returned a string (or I don't remember).

My response was to what you said about your code breaking:
Quote:However I DID have code breaking because it was expecting an integer and count_all_results returns a string.

Checking data type or type casting has always been my thing.
#12

[eluser]jedd[/eluser]
Hmm .. I can understand the point you're making (or suggesting) - that because it's a CI library, it could 'break the tradition' of PHP returning strings everywhere. But I stick to my initial observation on that approach - it renders your code very reliant on this particular framework. I don't expect or intend to shuffle between frameworks, but I know a few people like to be able to have portable code as they often have to lift their code and wedge it into extant (and different-framework-based) projects.

I think there's also an experience or background issue here. Those people that learnt PHP as their first real programming language are unlikely to be fussed or concerned about this - either they rely on PHP's loose typing, and happily (or obliviously) compare ints to strings to whatever, or if they need something to be a certain type they'll cast it on the fly (if they even know of this feature). A friend recently told me they'd only just discovered the === evaluator, for example, and had been coding some pretty big apps for years.

If you come from a background of more 'traditional' languages - C is the obvious and most likely candidate - then you're going to be far more aware of, and consequently far more careful with, typing.

Aside - my languages, in order of acquisition (and forgetting of) : BASIC, Assembler, COBOL, PROLOG, C, shell script, PHP. Perhaps atypically, I have totally embraced the idea of very loose typing - I think I'd suffer quite badly if I had to return to a language that was more strict.

With regards Samuel's problem (wanting to feed INT types into a JS function, and having it break if they were numbers wrapped in apostrophes) but I'm not sure about the exact nature of your code breakage - I'm tempted to think this is something that should be pushed back onto the function taking the data to sanitise / convert as necessary, rather than casting on data acquisition/creation/passing. There's a phrase I heard once to describe how you should implement networking protocols - something to the effect of 'Be liberal with what you accept, be strict with what you send'. I like this approach, and try to do it with my code as best I can. I have a function that will lookup a user's fullname given the user_id - and if I was in a genuine OOP environment I'd have a separate but identically named function that would provide fullname if the login_name was supplied. With PHP I just have an IF at the start that identifies the type (in the sense of is_numeric()) and provides the same effect (the function doesn't care what type of unique identifying data it's given). I'm sure other people do similar things, as a response to, and to take advantage of, loose typing.
#13

[eluser]Jondolar[/eluser]
The documentation says it returns an integer so this is a bug.

IMO, it doesn't make sense to return different types based on different database back ends. That's the point of abstraction, the lower level databases can be swapped out without changing your code.
#14

[eluser]TheFuzzy0ne[/eluser]
Well spotted. ...And welcome to the CodeIgniter forums. Smile




Theme © iAndrew 2016 - Forum software by © MyBB