[ciapug] Re: Re: yeah, weakly typed languages
Mike Parks
mparks at captainjack.com
Wed Apr 4 12:44:11 CDT 2007
"===" compares on equal text and type. "01234" == 1234 are equally
compared as string values equals true. But "01234" === 1234 compared as
a string value is true, but "01234" is a string and 1234 is an integer
will return false with "==="
ciapug-request at cialug.org wrote:
> Send ciapug mailing list submissions to
> ciapug at cialug.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://cialug.org/mailman/listinfo/ciapug
> or, via email, send a message with subject or body 'help' to
> ciapug-request at cialug.org
>
> You can reach the person managing the list at
> ciapug-owner at cialug.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of ciapug digest..."
>
>
> Today's Topics:
>
> 1. MySQL conference in Omaha yesterday (carl-olsen at mchsi.com)
> 2. Re: MySQL conference in Omaha yesterday (carl-olsen at mchsi.com)
> 3. yeah, weakly typed languages (Barry Von Ahsen)
> 4. Re: yeah, weakly typed languages (carl-olsen at mchsi.com)
> 5. Re: yeah, weakly typed languages (carl-olsen at mchsi.com)
> 6. Re: yeah, weakly typed languages (carl-olsen at mchsi.com)
> 7. Re: yeah, weakly typed languages (Dave J. Hala Jr.)
> 8. Re: yeah, weakly typed languages (carl-olsen at mchsi.com)
> 9. Re: yeah, weakly typed languages (carl-olsen at mchsi.com)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 04 Apr 2007 13:35:39 +0000
> From: carl-olsen at mchsi.com
> Subject: [ciapug] MySQL conference in Omaha yesterday
> To: ciapug at cialug.org
> Message-ID:
> <040420071335.12652.4613A9AB0002B9430000316C219791332903010CD2079C080C03BF020A9C0401D3049D0E0C at mchsi.com>
>
>
> Some of the things I learned yesterday:
>
> 1. Never use pconnect (the persistent connection function is going to be removed from PHP 6).
>
> 2. Always use prepared statements (requires mysqli).
>
> 3. Never use mysqli unless you are using prepared statements or other functions that do not exist in mysql (mysql runs faster).
>
> 4. Rarely use stored procedures because they are per thread (unlike other databases). They are not compiled and stored like they are in other databases. I think they are compiled at the start of a thread, but not permanently. I'm not sure I caught all the details on this, but its possible that stored procedure functionality will be improved in future releases of MySQL. Right now, their functionality is fairly crude.
>
> 5. Never use a function on a condition (filter) in a "WHERE" clause because indexing will be ignored. The function has to run on every row, so it's just a sequential operation because of the function being used on the column.
>
> 6. Triggers are okay because they don't run as often as stored procedures and have a lighter footprint.
>
> 7. EXPLAIN will show you how MySQL actually executes an SQL query (which is often different than the way it is written).
>
> 8. Two additional table types (in addition to InnoDB, MyISAM and others), are MEMORY and ARCHIVE. I think the one that will likely get full text indexing as well as support for foreign keys was called "Falcon" or something like that (I never heard of it before). MyISAM is going to run faster than InnoDB in most cases because it is not as complicated as InnoDB.
>
> 9. To get a query to show vertically from the command line instead of in a table use "/G" switch at the end of the query.
>
> --
> Carl Olsen, MCSE
> Web Developer
> Marketing and Communications
> Drake University
> 2507 University Avenue
> 115 Old Main
> Des Moines, Iowa 50311-4505
> Phone: 515-271-2986
> Fax: 515-271-3798
> Carl.Olsen at drake.edu
> www.drake.edu
>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 04 Apr 2007 13:57:17 +0000
> From: carl-olsen at mchsi.com
> Subject: Re: [ciapug] MySQL conference in Omaha yesterday
> To: ciapug at cialug.org, ciapug at cialug.org
> Cc: carl-olsen at mchsi.com
> Message-ID:
> <040420071357.2782.4613AEBD00011AB600000ADE219791332903010CD2079C080C03BF020A9C0401D3049D0E0C at mchsi.com>
>
>
> Another interesting thing was query caching. If you use the MySQL function for calculating a date inside a query, it will not cache the query - but always executes the query. Using a PHP function to calculate the date creates a static query string and MySQL will cache the results and return the result from cache instead of re-running the query every time it is called.
>
> -------------- Original message ----------------------
> From: carl-olsen at mchsi.com
>
>> Some of the things I learned yesterday:
>>
>> 1. Never use pconnect (the persistent connection function is going to be removed
>> from PHP 6).
>>
>> 2. Always use prepared statements (requires mysqli).
>>
>> 3. Never use mysqli unless you are using prepared statements or other functions
>> that do not exist in mysql (mysql runs faster).
>>
>> 4. Rarely use stored procedures because they are per thread (unlike other
>> databases). They are not compiled and stored like they are in other databases.
>> I think they are compiled at the start of a thread, but not permanently. I'm
>> not sure I caught all the details on this, but its possible that stored
>> procedure functionality will be improved in future releases of MySQL. Right
>> now, their functionality is fairly crude.
>>
>> 5. Never use a function on a condition (filter) in a "WHERE" clause because
>> indexing will be ignored. The function has to run on every row, so it's just a
>> sequential operation because of the function being used on the column.
>>
>> 6. Triggers are okay because they don't run as often as stored procedures and
>> have a lighter footprint.
>>
>> 7. EXPLAIN will show you how MySQL actually executes an SQL query (which is
>> often different than the way it is written).
>>
>> 8. Two additional table types (in addition to InnoDB, MyISAM and others), are
>> MEMORY and ARCHIVE. I think the one that will likely get full text indexing as
>> well as support for foreign keys was called "Falcon" or something like that (I
>> never heard of it before). MyISAM is going to run faster than InnoDB in most
>> cases because it is not as complicated as InnoDB.
>>
>> 9. To get a query to show vertically from the command line instead of in a table
>> use "/G" switch at the end of the query.
>>
>> --
>> Carl Olsen, MCSE
>> Web Developer
>> Marketing and Communications
>> Drake University
>> 2507 University Avenue
>> 115 Old Main
>> Des Moines, Iowa 50311-4505
>> Phone: 515-271-2986
>> Fax: 515-271-3798
>> Carl.Olsen at drake.edu
>> www.drake.edu
>>
>> _______________________________________________
>> ciapug mailing list
>> ciapug at cialug.org
>> http://cialug.org/mailman/listinfo/ciapug
>>
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 04 Apr 2007 11:15:33 -0500
> From: Barry Von Ahsen <barry at vonahsen.com>
> Subject: [ciapug] yeah, weakly typed languages
> To: ciapug at cialug.org
> Message-ID: <4613CF25.1070404 at vonahsen.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> echo "phpversion: ".phpversion()."<br>";
> $a = "01234";
> $b = "1234";
> echo "a:". $a."<br>";
> echo "b:". $b."<br>";
> if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
> if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
> echo "gettype(a):". gettype($a)."<br>";
> echo "gettype(b):". gettype($b)."<br>";
>
> $c = "0foo";
> $d = "foo";
> echo "c:". $c."<br>";
> echo "d:". $d."<br>";
> if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
> if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
>
> output:
> phpversion: 4.4.0
> a:01234
> b:1234
> a==b
> a!==b
> gettype(a):string
> gettype(b):string
> c:0foo
> d:foo
> c!=d
> c!==d
>
> I totally understand why "01234"==1234, but not why "01234"=="1234". If
> I'm doing string=>string, no conversion should happen. However, if it
> does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
>
> -barry
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 04 Apr 2007 16:36:29 +0000
> From: carl-olsen at mchsi.com
> Subject: Re: [ciapug] yeah, weakly typed languages
> To: barry at vonahsen.com, ciapug at cialug.org, ciapug at cialug.org
> Cc: Barry Von Ahsen <barry at vonahsen.com>
> Message-ID:
> <040420071636.8196.4613D40D0003811900002004219791332903010CD2079C080C03BF020A9C0401D3049D0E0C at mchsi.com>
>
>
> I have never used this, but isn't "===" a function that might solve this?
>
> I think "==" is equality, and "===" is absolute equality.
>
> Carl
>
> -------------- Original message ----------------------
> From: Barry Von Ahsen <barry at vonahsen.com>
>
>> echo "phpversion: ".phpversion()."<br>";
>> $a = "01234";
>> $b = "1234";
>> echo "a:". $a."<br>";
>> echo "b:". $b."<br>";
>> if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
>> if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
>> echo "gettype(a):". gettype($a)."<br>";
>> echo "gettype(b):". gettype($b)."<br>";
>>
>> $c = "0foo";
>> $d = "foo";
>> echo "c:". $c."<br>";
>> echo "d:". $d."<br>";
>> if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
>> if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
>>
>> output:
>> phpversion: 4.4.0
>> a:01234
>> b:1234
>> a==b
>> a!==b
>> gettype(a):string
>> gettype(b):string
>> c:0foo
>> d:foo
>> c!=d
>> c!==d
>>
>> I totally understand why "01234"==1234, but not why "01234"=="1234". If
>> I'm doing string=>string, no conversion should happen. However, if it
>> does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
>>
>> -barry
>>
>>
>> _______________________________________________
>> ciapug mailing list
>> ciapug at cialug.org
>> http://cialug.org/mailman/listinfo/ciapug
>>
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 04 Apr 2007 16:42:05 +0000
> From: carl-olsen at mchsi.com
> Subject: Re: [ciapug] yeah, weakly typed languages
> To: barry at vonahsen.com, ciapug at cialug.org, ciapug at cialug.org
> Cc: Barry Von Ahsen <barry at vonahsen.com>
> Message-ID:
> <040420071642.12428.4613D55D0001D5DB0000308C219791332903010CD2079C080C03BF020A9C0401D3049D0E0C at mchsi.com>
>
>
> I agree that is annoying, but it is producing the correct answer when you use "===" and what appears to be an incorrect answer when you use "==". Since I have never used "===" for anything, that would explain why it exists and would also prove that what you are experiencing is the intended behavior. I could not begin to guess why they would want those two strings to be equal, but there must be some reason for it.
>
>
> -------------- Original message ----------------------
> From: Barry Von Ahsen <barry at vonahsen.com>
>
>> echo "phpversion: ".phpversion()."<br>";
>> $a = "01234";
>> $b = "1234";
>> echo "a:". $a."<br>";
>> echo "b:". $b."<br>";
>> if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
>> if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
>> echo "gettype(a):". gettype($a)."<br>";
>> echo "gettype(b):". gettype($b)."<br>";
>>
>> $c = "0foo";
>> $d = "foo";
>> echo "c:". $c."<br>";
>> echo "d:". $d."<br>";
>> if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
>> if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
>>
>> output:
>> phpversion: 4.4.0
>> a:01234
>> b:1234
>> a==b
>> a!==b
>> gettype(a):string
>> gettype(b):string
>> c:0foo
>> d:foo
>> c!=d
>> c!==d
>>
>> I totally understand why "01234"==1234, but not why "01234"=="1234". If
>> I'm doing string=>string, no conversion should happen. However, if it
>> does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
>>
>> -barry
>>
>>
>> _______________________________________________
>> ciapug mailing list
>> ciapug at cialug.org
>> http://cialug.org/mailman/listinfo/ciapug
>>
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Wed, 04 Apr 2007 16:44:23 +0000
> From: carl-olsen at mchsi.com
> Subject: Re: [ciapug] yeah, weakly typed languages
> To: barry at vonahsen.com, ciapug at cialug.org, ciapug at cialug.org
> Cc: Barry Von Ahsen <barry at vonahsen.com>
> Message-ID:
> <040420071644.13932.4613D5E700067F0D0000366C219791332903010CD2079C080C03BF020A9C0401D3049D0E0C at mchsi.com>
>
>
> It's taking a while for this to sink in. The difference between the strings is that one is all numeric characters and the other is mixed. Don't ask me why this makes a difference. I'm just pointing it out and accepting that it explains the difference.
>
> -------------- Original message ----------------------
> From: Barry Von Ahsen <barry at vonahsen.com>
>
>> echo "phpversion: ".phpversion()."<br>";
>> $a = "01234";
>> $b = "1234";
>> echo "a:". $a."<br>";
>> echo "b:". $b."<br>";
>> if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
>> if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
>> echo "gettype(a):". gettype($a)."<br>";
>> echo "gettype(b):". gettype($b)."<br>";
>>
>> $c = "0foo";
>> $d = "foo";
>> echo "c:". $c."<br>";
>> echo "d:". $d."<br>";
>> if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
>> if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
>>
>> output:
>> phpversion: 4.4.0
>> a:01234
>> b:1234
>> a==b
>> a!==b
>> gettype(a):string
>> gettype(b):string
>> c:0foo
>> d:foo
>> c!=d
>> c!==d
>>
>> I totally understand why "01234"==1234, but not why "01234"=="1234". If
>> I'm doing string=>string, no conversion should happen. However, if it
>> does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
>>
>> -barry
>>
>>
>> _______________________________________________
>> ciapug mailing list
>> ciapug at cialug.org
>> http://cialug.org/mailman/listinfo/ciapug
>>
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Wed, 04 Apr 2007 11:45:02 -0500
> From: "Dave J. Hala Jr." <dave at 58ghz.net>
> Subject: Re: [ciapug] yeah, weakly typed languages
> To: PHP List <ciapug at cialug.org>
> Message-ID: <1175705102.31767.15.camel at localhost.localdomain>
> Content-Type: text/plain
>
> I *think* I saw that in reference to php 5 or soon to be php 6
> somewhere...
>
> On Wed, 2007-04-04 at 11:36, carl-olsen at mchsi.com wrote:
>
>> I have never used this, but isn't "===" a function that might solve this?
>>
>> I think "==" is equality, and "===" is absolute equality.
>>
>> Carl
>>
>> -------------- Original message ----------------------
>> From: Barry Von Ahsen <barry at vonahsen.com>
>>
>>> echo "phpversion: ".phpversion()."<br>";
>>> $a = "01234";
>>> $b = "1234";
>>> echo "a:". $a."<br>";
>>> echo "b:". $b."<br>";
>>> if($a == $b) { echo "a==b"; } else { echo "a!=b"; } echo "<br>";
>>> if($a === $b) { echo "a===b"; } else { echo "a!==b"; } echo "<br>";
>>> echo "gettype(a):". gettype($a)."<br>";
>>> echo "gettype(b):". gettype($b)."<br>";
>>>
>>> $c = "0foo";
>>> $d = "foo";
>>> echo "c:". $c."<br>";
>>> echo "d:". $d."<br>";
>>> if($c == $d) { echo "c==d"; } else { echo "c!=d"; } echo "<br>";
>>> if($c === $d) { echo "c===d"; } else { echo "c!==d"; } echo "<br>";
>>>
>>> output:
>>> phpversion: 4.4.0
>>> a:01234
>>> b:1234
>>> a==b
>>> a!==b
>>> gettype(a):string
>>> gettype(b):string
>>> c:0foo
>>> d:foo
>>> c!=d
>>> c!==d
>>>
>>> I totally understand why "01234"==1234, but not why "01234"=="1234". If
>>> I'm doing string=>string, no conversion should happen. However, if it
>>> does, why doesn't "0foo"=>0 and "foo"=>0 so "0foo"=="foo" also?!?
>>>
>>> -barry
>>>
>>>
>>> _______________________________________________
>>> ciapug mailing list
>>> ciapug at cialug.org
>>> http://cialug.org/mailman/listinfo/ciapug
>>>
>> _______________________________________________
>> ciapug mailing list
>> ciapug at cialug.org
>> http://cialug.org/mailman/listinfo/ciapug
>>
--
<><><><><><><><><><><><><><><><><>
Mike Parks
Captain Jack Communications
WebSite Development and Hosting
www.captainjack.com
Phone: 515-964-8500
Fax: 515-964-4685
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/ciapug/attachments/20070404/637d4088/attachment-0001.html
More information about the ciapug
mailing list