Welcome Guest, Not a member yet? Register   Sign In
Bool in session is turned into string
#12

[eluser]BrianDHall[/eluser]
[quote author="überfuzz" date="1254865948"]Ok, I vote downside. We just got a clear case where a core operator was used to check value a-n-d type. Is there any one sitting on the info about a reason why every session-value is turned into a string in CI?

Edit a earlier post, teacher allowed type being altered, IN A CONTROLLED FASHION. Furthermore, this tells us that JAVA i type dynamic, don't it. ;-)[/quote]

For the 'why', Phil posted the code as to when it happens. All session variables are fed to str_replace, which explicitly returns a string - so the boolean is cast to a string. Actually, everything is cast to a string because of str_replace().

On Java, actually I believe it isn't type dynamic (working off memory here, it's been years), you must tell it what type you want if it isn't the default that the object returns. So if you want a string you have to call Object.toString, etc - everything in Java is an object, I believe even Strings are objects. In PHP, everything is most certainly not an object.

PHP manages references and variable types at run time attempting to maximize performance and minimize the need to ever consider what type a variable is.

PHP is usually very smart about this, thus the rarity of problems - but CI is calling a PHP function that, by its very nature, takes a string (and will cast a provided variable to a string if it isn't a string) and returns a string. Thus your frustration in the magically changing types.

I suppose you might make the case that this is actually a bug, and CI should check to make sure something is a string before running str_replace() - thereby converting it to a string even if it shouldn't be.


Messages In This Thread
Bool in session is turned into string - by El Forum - 10-06-2009, 12:54 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 01:39 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 02:29 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 02:32 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 02:52 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 02:55 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 03:14 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 03:39 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 04:22 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 08:28 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 10:52 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 11:01 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 11:55 AM
Bool in session is turned into string - by El Forum - 10-06-2009, 04:36 PM
Bool in session is turned into string - by El Forum - 10-06-2009, 08:46 PM
Bool in session is turned into string - by El Forum - 10-07-2009, 12:39 AM
Bool in session is turned into string - by El Forum - 10-08-2009, 09:59 AM
Bool in session is turned into string - by El Forum - 10-08-2009, 11:45 AM
Bool in session is turned into string - by El Forum - 12-26-2009, 06:14 PM
Bool in session is turned into string - by El Forum - 03-29-2010, 03:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB