subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
Takeoded
g2cjz2g
<|sols|><|sot|>breaking-to-fix in_array() for PHP8: OK. breaking-to-fix DateTime::ISO8601 for PHP8? no can do (DateTime::ISO8601 is not legal ISO8601)<|eot|><|sol|>https://3v4l.org/B0Jqh<|eol|><|sor|>Well the thing is that it is a valid ISO8601 format: > [Time zones](https://en.wikipedia.org/wiki/Time_zone) in ISO 8601 are represented as local time (with the location unspecified), as [UTC](https://en.wikipedia.org/wiki/UTC), or as an offset from UTC. > > > ><time>Z <time>hh:mm <time>hhmm <time>hh Pulled from: [https://en.wikipedia.org/wiki/ISO\_8601#Time\_zone\_designators](https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators) ISO8601 has multiple *valid* representations, making PHP's `DateTime::ISO8601` completely within the specification of the standard. Moreover, the change to `in_array()` has *nothing* to do with the DateTime extension<|eor|><|soopr|>No it's not valid ISO8601 > ISO8601 has multiple valid representations that is true, for example Basic format: YYYYMMDD Example: 19850412 Extended format: YYYY-MM-DD Example: 1985-04-12 > making PHP's DateTime::ISO8601 completely within the specification of the standard that's not true (or at the very least it's not true in ISO8601:2004, the only revision i have access to), the first part `1970-01-01T01:00:00` is a valid extended-format, and now for adding the timezone, in **BASIC** format, this is legal (per section `4.3.2 Complete representations`): YYYYMMDDThhmmsshhmm 19850412T101530+0400 YYYYMMDDThhmmsshh 19850412T101530+04 - that's legal in basic format, and is ***how PHP adds the timezone***, but that's not legal in extended format, here's how to add it in extended format: &nbsp; Extended format: YYYY-MM-DDThh:mm:ss Example: 1985-04-12T10:15:30 YYYY-MM-DDThh:mm:ssZ 1985-04-12T10:15:30Z YYYY-MM-DDThh:mm:sshh:mm 1985-04-12T10:15:30+04:00 YYYY-MM-DDThh:mm:sshh 1985-04-12T10:15:30+04 - now what does php do? it starts out with legal extended format illegal basic format `1970-01-01T01:00:00` ... and then it ends with legal basic format illegal extended format: `+0100` - in all of ISO8601:2004 i can't find a single example where the standard is ***mixing*** extended format with basic format, and i can't find a single statement saying "you're allowed to mix basic format with extended format" either. PHP's DateTime::ISO8601 format is a *mix* of starting with legal extended format, and ending with legal basic format, that mix is not allowed per ISO8601:2004. edit: found this, which quite clearly states that mixing extended with basic is *NOT* legal, quoting section 4.3.3 of ISO8601:2004: For reduced accuracy, decimal or expanded representations of date and time of day, any of the representations in 4.1.2 (calendar dates), 4.1.3 (ordinal dates) or 4.1.4 (week dates) followed immediately by the time designator [T] may be combined with any of the representations in 4.2.2.2 through 4.2.2.4 (local time), 4.2.4 (UTC of day) or 4.2.5.2 (local time and the difference from UTC) provided that (...skipped stuff...) d) the expression shall either be completely in basic format, in which case the minimum number of separators necessary for the required expression is used, or completely in extended format, in which case additional separators shall be used in accordance with 4.1 and 4.2.<|eoopr|><|eols|><|endoftext|>
7
lolphp
barubary
cx3e70
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|eoss|><|endoftext|>
25
lolphp
teizhen
eyi7mwq
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>Imagine not using an editor in 2019.<|eor|><|eoss|><|endoftext|>
17
lolphp
oldskater
eyidkpo
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>Imagine not using an editor in 2019.<|eor|><|soopr|>What counts as an editor? I tested PHPStorm. If you use `Ctrl+Shift+/`, it blindly wraps `/*` and `*/` around the whole thing (which breaks as described); if you use `Ctrl-/`, it blindly slaps `//` in front of each line (which breaks as described). You would need an editor with custom logic for commenting out PHP code specifically. It would have to come up with a convention for escaping `?>` in single-line comments (and escaping the escape convention elsewhere), and then undoing that in its "uncomment" implementation. I would imagine most IDEs and editors get some part of this wrong.<|eoopr|><|sor|>I tested this in PhpStorm with Ctrl-/ and got this result: <?php // //$code = '...'; //// ... // //// PHP comments can have the form /* ... */ or // ... or # ... //$code = stripComments($code); // /*if ( $code === '' || substr($code, 0, 2) === '?>' ) {*/ // // end of code // // ... //} This is correct and does not break.<|eor|><|eoss|><|endoftext|>
17
lolphp
captainramen
eyja60d
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>You could also use source control<|eor|><|eoss|><|endoftext|>
13
lolphp
barubary
eyic7fu
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>Imagine not using an editor in 2019.<|eor|><|soopr|>What counts as an editor? I tested PHPStorm. If you use `Ctrl+Shift+/`, it blindly wraps `/*` and `*/` around the whole thing (which breaks as described); if you use `Ctrl-/`, it blindly slaps `//` in front of each line (which breaks as described). You would need an editor with custom logic for commenting out PHP code specifically. It would have to come up with a convention for escaping `?>` in single-line comments (and escaping the escape convention elsewhere), and then undoing that in its "uncomment" implementation. I would imagine most IDEs and editors get some part of this wrong.<|eoopr|><|eoss|><|endoftext|>
7
lolphp
barubary
eyia47n
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>[deleted]<|eor|><|soopr|>Sadly that doesn't work everywhere, e.g. if you just want to comment out one method in a class. I agree with outright removing code (and restoring from VCS if necessary) for middle- to long-term changes, but when I'm just playing around and fiddling with things, I find it easier to comment out code.<|eoopr|><|eoss|><|endoftext|>
7
lolphp
geerlingguy
eyj1tdw
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>Imagine not using an editor in 2019.<|eor|><|soopr|>What counts as an editor? I tested PHPStorm. If you use `Ctrl+Shift+/`, it blindly wraps `/*` and `*/` around the whole thing (which breaks as described); if you use `Ctrl-/`, it blindly slaps `//` in front of each line (which breaks as described). You would need an editor with custom logic for commenting out PHP code specifically. It would have to come up with a convention for escaping `?>` in single-line comments (and escaping the escape convention elsewhere), and then undoing that in its "uncomment" implementation. I would imagine most IDEs and editors get some part of this wrong.<|eoopr|><|sor|>I tested this in PhpStorm with Ctrl-/ and got this result: <?php // //$code = '...'; //// ... // //// PHP comments can have the form /* ... */ or // ... or # ... //$code = stripComments($code); // /*if ( $code === '' || substr($code, 0, 2) === '?>' ) {*/ // // end of code // // ... //} This is correct and does not break.<|eor|><|sor|>Same result in Sublime Text 3.<|eor|><|eoss|><|endoftext|>
7
lolphp
barubary
eyjii9a
<|soss|><|sot|>Commenting out code<|eot|><|sost|>Commenting out a chunk of code is unnecessarily hard in PHP. Consider the following code snippet, hypothetically analyzing a piece of PHP in PHP: <?php $code = '...'; // ... // PHP comments can have the form /* ... */ or // ... or # ... $code = stripComments($code); if ( $code === '' || substr($code, 0, 2) === '?>' ) { // end of code // ... } We want to comment out all of it. Our first instinct might be to just surround the whole thing in `/* ... */`. That doesn't work because the code already contains `*/`, terminating the comment halfway through. C has the same problem, but offers an excellent alternative: #if 0 ... #endif This relies on the preprocessor, however, so is not an option in PHP. In other languages with single-line comments (e.g. C or JavaScript with `//`, or Perl or the shell with `#`), you can just insert a comment marker at the beginning of each line. Any code editor worth its salt will make this easy. <?php # $code = '...'; # // ... # // PHP comments can have the form /* ... */ or // ... or # ... # $code = stripComments($code); # if ( $code === '' || substr($code, 0, 2) === '?>' ) { # // end of code # // ... # } However, that doesn't fly in PHP either because the character sequence `?>` interrupts single-line comments and ends interpretation of PHP code. (Single-line comments are the only syntactic construct that `?>` can interrupt; e.g. block comments or string literals are immune.) Thus comment vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv # if ( $code === '' || substr($code, 0, 2) === '?>' ) { ^^^^^ "HTML" will produce `' ) {` as output because it's outside of the `<?php ... ?>` pseudo-tag. There is no simple general way to comment out an arbitrary piece of PHP code. You always have to scan through and escape some parts.<|eost|><|sor|>Imagine not using an editor in 2019.<|eor|><|soopr|>What counts as an editor? I tested PHPStorm. If you use `Ctrl+Shift+/`, it blindly wraps `/*` and `*/` around the whole thing (which breaks as described); if you use `Ctrl-/`, it blindly slaps `//` in front of each line (which breaks as described). You would need an editor with custom logic for commenting out PHP code specifically. It would have to come up with a convention for escaping `?>` in single-line comments (and escaping the escape convention elsewhere), and then undoing that in its "uncomment" implementation. I would imagine most IDEs and editors get some part of this wrong.<|eoopr|><|sor|>I tested this in PhpStorm with Ctrl-/ and got this result: <?php // //$code = '...'; //// ... // //// PHP comments can have the form /* ... */ or // ... or # ... //$code = stripComments($code); // /*if ( $code === '' || substr($code, 0, 2) === '?>' ) {*/ // // end of code // // ... //} This is correct and does not break.<|eor|><|soopr|>Oh, neat. Maybe you have a newer version. How does it deal with if ( $code === '*/' || substr($code, 0, 2) === '?>' ) { ?<|eoopr|><|eoss|><|endoftext|>
5
lolphp
pgl
2yk2sq
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|eols|><|endoftext|>
22
lolphp
pgl
cpa86zh
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|soopr|>Explanation: the reason for this behaviour is that `__get()` uses the internal `__isset()`, which returns false on a protected variable.<|eoopr|><|eols|><|endoftext|>
19
lolphp
kingguru
cpa97cu
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|soopr|>Explanation: the reason for this behaviour is that `__get()` uses the internal `__isset()`, which returns false on a protected variable.<|eoopr|><|sor|>But how can var_dump() access a protected member in the first place? The setBar() method explicitly sets the value of the protected variable "bar", so it's not like it dynamically adds a new (public) member that shadows the previous "bar" value. I'm confused, but I guess that was the entire point of you post :-)<|eor|><|eols|><|endoftext|>
15
lolphp
pgl
cpa9cdw
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|soopr|>Explanation: the reason for this behaviour is that `__get()` uses the internal `__isset()`, which returns false on a protected variable.<|eoopr|><|sor|>But how can var_dump() access a protected member in the first place? The setBar() method explicitly sets the value of the protected variable "bar", so it's not like it dynamically adds a new (public) member that shadows the previous "bar" value. I'm confused, but I guess that was the entire point of you post :-)<|eor|><|soopr|>`var_dump` can access the protected member because there's a `__get()` method in place that bypasses visibility settings.<|eoopr|><|eols|><|endoftext|>
13
lolphp
pgl
cpb90jd
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|soopr|>I wouldn't expect `empty()` to return false in this case. Here: var_dump(empty($obj->bar)); // bool(true) $var = $obj->bar; var_dump(empty($var)); // bool(false) That's weird.<|eoopr|><|eols|><|endoftext|>
12
lolphp
cite-reader
cpaiq6e
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|sor|>We generally expect things to follow the substitution model of execution. When they don't, confusion is the inevitable result. In this case, the natural expectation would be this reduction sequence: `empty($obj->bar)` `empty('Hello World')` `false`. This is *pretty much* what Python does when you call `hasAttr`, for example. It's not what PHP does, though, because `empty` is magic.<|eor|><|eols|><|endoftext|>
7
lolphp
pgl
cpb9cvl
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|soopr|>I wouldn't expect `empty()` to return false in this case. Here: var_dump(empty($obj->bar)); // bool(true) $var = $obj->bar; var_dump(empty($var)); // bool(false) That's weird.<|eoopr|><|sor|>That is exactly what I explained? empty($var); checks if $var *exists* in the current scope. It does. empty($obj->bar); checks if the *instance variable* $bar [not a catch-all getter] exists on $obj in *that same scope*, which it does not per definition since it's private. empty() and isset() being design to check for the existence of the actual variables [without causing an error/warning if they do not], not just wether or not something returns a value. The value of $obj->bar only relates to the private instance variable $obj::$bar by dynamic code and does not constitute the existence of the variable. *Edit: To be clear, the reason why the first returns true and the second false is that in the first there is no such actual variable (as seen from the outside, i.e. private visibility) and in the second the local variable has a value that was received via the magically called __get() method.*<|eor|><|soopr|>I'm not sure I understand what you're saying. But, when you assign a variable to another variable, you wouldn't expect a different return value from `empty()` on those two variables. The assignment should mean that they're the same.<|eoopr|><|eols|><|endoftext|>
6
lolphp
pgl
cpb9i4r
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|soopr|>I wouldn't expect `empty()` to return false in this case. Here: var_dump(empty($obj->bar)); // bool(true) $var = $obj->bar; var_dump(empty($var)); // bool(false) That's weird.<|eoopr|><|sor|>That is exactly what I explained? empty($var); checks if $var *exists* in the current scope. It does. empty($obj->bar); checks if the *instance variable* $bar [not a catch-all getter] exists on $obj in *that same scope*, which it does not per definition since it's private. empty() and isset() being design to check for the existence of the actual variables [without causing an error/warning if they do not], not just wether or not something returns a value. The value of $obj->bar only relates to the private instance variable $obj::$bar by dynamic code and does not constitute the existence of the variable. *Edit: To be clear, the reason why the first returns true and the second false is that in the first there is no such actual variable (as seen from the outside, i.e. private visibility) and in the second the local variable has a value that was received via the magically called __get() method.*<|eor|><|soopr|>I'm not sure I understand what you're saying. But, when you assign a variable to another variable, you wouldn't expect a different return value from `empty()` on those two variables. The assignment should mean that they're the same.<|eoopr|><|sor|>$obj->bar is *not* a variable. It's a function call to __get(), the *variable* $bar on the object $obj does not exist because it's private and therefor *invisible*. Since it's a function call there is no actual binding between $obj::$bar (protected var) and the call to $obj::__get("bar"). __get() just happens to return the variable in that instance but it could as easily have returned another one because it's a dynamic getter, it does not create or masquerade as an actual instance variable. __get() is a fallback that is called after it has already been decided that the object does not have any [visible/existing, same thing] instance variable of a given name. (In other words, the mechanics of empty()/isset() is what is actually used to determine wether or not __get() should be called at all. It essentially only gets called when empty() is true.) empty() is 100% consistent in it's behaviour and not really magic at all, however __get() is a magic function [and named as such] and the dual underscore indicates that as well. If one does not want to take magic stuff into consideration then one should avoid the explicitly defined magic functions, and use the __ prefix to help identify them. But there is no real issue here except not fully understanding what empty() does and when it's used, and what __get() does and when it's actually called, but they are both clearly documented to show this behaviour. (And I don't really find it valid when people use assumptions from other languages and then get upset when they were wrong in those assumptions.) **TL;DR** You are not assigning a variable from a variable, you are assigning a variable from a function (__get() method) that is called with a *variable-like syntax*. But it's still a function.<|eor|><|soopr|>OK. It's still weird.<|eoopr|><|eols|><|endoftext|>
6
lolphp
cparen
cpe62hk
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|sor|>We generally expect things to follow the substitution model of execution. When they don't, confusion is the inevitable result. In this case, the natural expectation would be this reduction sequence: `empty($obj->bar)` `empty('Hello World')` `false`. This is *pretty much* what Python does when you call `hasAttr`, for example. It's not what PHP does, though, because `empty` is magic.<|eor|><|sor|>> because `empty` is magic. That's the word PHP uses for things that other languages would call 'intrinsics', 'macros' or 'syntax', right? "empty()" doesn't behave like a function call. Lisps tend to get into similar confusion. Function calls are written like "(f x)" where "f" is a function, and "x" an argument, but "(quote a)" is not a function call. It's a "special form" that gets special treatment because "quote" is special. IOW, "magic function" == "special form", right?<|eor|><|eols|><|endoftext|>
5
lolphp
cite-reader
cpaqeqw
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|sor|>We generally expect things to follow the substitution model of execution. When they don't, confusion is the inevitable result. In this case, the natural expectation would be this reduction sequence: `empty($obj->bar)` `empty('Hello World')` `false`. This is *pretty much* what Python does when you call `hasAttr`, for example. It's not what PHP does, though, because `empty` is magic.<|eor|><|sor|>But that would apply to the empty() statement in general. What is the significance of the `__get`?<|eor|><|sor|>`__get` in PHP is pretty much Python's `__get__`, if you're familiar with that language. It's a method that the language defines, which intercepts property access and runs your code instead. I'm not a huge fan, because it replaces something that looks like it should be a dictionary lookup at worst with arbitrarily complex code, but it can certainly be useful. The end result of defining this kind of method is that your object's effective property set ends up being defined by whatever possibly-non-terminating procedure you defined it as. In this case, from the perspective of code outside the scope of `foo` itself, instances of `foo` have a property named `bar`. Mostly. *Unless* you use one of the things provided as primitives, which won't be affected by `__get` and will give you weird results. This weirdness, by the way, is why Python's `hasattr` actually calls `getattr` under the hood, which is a function that calls `__get__` if it exists, because hey it might raise `AttributeError`: Python cares a fair amount about providing a logically consistent view of the objects you are manipulating. PHP, not so much.<|eor|><|eols|><|endoftext|>
5
lolphp
edave64
cpaqzxz
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|sor|>We generally expect things to follow the substitution model of execution. When they don't, confusion is the inevitable result. In this case, the natural expectation would be this reduction sequence: `empty($obj->bar)` `empty('Hello World')` `false`. This is *pretty much* what Python does when you call `hasAttr`, for example. It's not what PHP does, though, because `empty` is magic.<|eor|><|sor|>But that would apply to the empty() statement in general. What is the significance of the `__get`?<|eor|><|sor|>`__get` in PHP is pretty much Python's `__get__`, if you're familiar with that language. It's a method that the language defines, which intercepts property access and runs your code instead. I'm not a huge fan, because it replaces something that looks like it should be a dictionary lookup at worst with arbitrarily complex code, but it can certainly be useful. The end result of defining this kind of method is that your object's effective property set ends up being defined by whatever possibly-non-terminating procedure you defined it as. In this case, from the perspective of code outside the scope of `foo` itself, instances of `foo` have a property named `bar`. Mostly. *Unless* you use one of the things provided as primitives, which won't be affected by `__get` and will give you weird results. This weirdness, by the way, is why Python's `hasattr` actually calls `getattr` under the hood, which is a function that calls `__get__` if it exists, because hey it might raise `AttributeError`: Python cares a fair amount about providing a logically consistent view of the objects you are manipulating. PHP, not so much.<|eor|><|sor|>Thank you for the explanation, but I already know what `__get` does. I was actually confused about the function of `empty`. I thought it clears a variable, but apperently it check IF a variable is empty. (Also, I am more of a ruby guy, where this would be done using the `method_missing` method)<|eor|><|eols|><|endoftext|>
5
lolphp
loptr
cpask2p
<|sols|><|sot|>empty() vs __get()<|eot|><|sol|>http://ideone.com/RVw5XK<|eol|><|sor|>I don't understand what you're objecting to here. empty() does exactly what it's supposed to, i.e. ignoring any virtualisation and looking for a literal property. It checks for the actual variable. This is literally the exact point of empty(), the property bar is invisible in that scope and therefor doesn't exist in that scope. What would you have it do instead in this scenario?<|eor|><|sor|>We generally expect things to follow the substitution model of execution. When they don't, confusion is the inevitable result. In this case, the natural expectation would be this reduction sequence: `empty($obj->bar)` `empty('Hello World')` `false`. This is *pretty much* what Python does when you call `hasAttr`, for example. It's not what PHP does, though, because `empty` is magic.<|eor|><|sor|>But that would apply to the empty() statement in general. What is the significance of the `__get`?<|eor|><|sor|>`__get` in PHP is pretty much Python's `__get__`, if you're familiar with that language. It's a method that the language defines, which intercepts property access and runs your code instead. I'm not a huge fan, because it replaces something that looks like it should be a dictionary lookup at worst with arbitrarily complex code, but it can certainly be useful. The end result of defining this kind of method is that your object's effective property set ends up being defined by whatever possibly-non-terminating procedure you defined it as. In this case, from the perspective of code outside the scope of `foo` itself, instances of `foo` have a property named `bar`. Mostly. *Unless* you use one of the things provided as primitives, which won't be affected by `__get` and will give you weird results. This weirdness, by the way, is why Python's `hasattr` actually calls `getattr` under the hood, which is a function that calls `__get__` if it exists, because hey it might raise `AttributeError`: Python cares a fair amount about providing a logically consistent view of the objects you are manipulating. PHP, not so much.<|eor|><|sor|>Thank you for the explanation, but I already know what `__get` does. I was actually confused about the function of `empty`. I thought it clears a variable, but apperently it check IF a variable is empty. (Also, I am more of a ruby guy, where this would be done using the `method_missing` method)<|eor|><|sor|>> but apperently it check IF a variable is empty. If a variable is empty *or non-existent*, which is a big difference since it actually introspects variable name stack. And the property $bar is non-existent from global scope since it's private.<|eor|><|eols|><|endoftext|>
5
lolphp
midir
2qhkca
<|soss|><|sot|>PHP warns about incompatible methods only if you also define the classes child-first<|eot|><|sost|>PHP's strict standards mode can tell you if you have overridden a method with a different number of arguments. For example, [the following shows an error](https://eval.in/237299) because `test()` is not compatible with `test($a)`: <?php error_reporting(E_ALL | E_STRICT); class cc extends c { function test() {} } class c { function test($a) {} } However, notice the classes are defined with the child `cc` first, then the parent class `c`. It turns out that if you define the classes in the more natural order, [you might not get any error](https://eval.in/237300) (depending on php.ini): <?php error_reporting(E_ALL | E_STRICT); class c { function test($a) {} } class cc extends c { function test() {} } Don't worry though, it's ["not a bug"](https://bugs.php.net/bug.php?id=46851).<|eost|><|eoss|><|endoftext|>
24
lolphp
barubary
cn6id6m
<|soss|><|sot|>PHP warns about incompatible methods only if you also define the classes child-first<|eot|><|sost|>PHP's strict standards mode can tell you if you have overridden a method with a different number of arguments. For example, [the following shows an error](https://eval.in/237299) because `test()` is not compatible with `test($a)`: <?php error_reporting(E_ALL | E_STRICT); class cc extends c { function test() {} } class c { function test($a) {} } However, notice the classes are defined with the child `cc` first, then the parent class `c`. It turns out that if you define the classes in the more natural order, [you might not get any error](https://eval.in/237300) (depending on php.ini): <?php error_reporting(E_ALL | E_STRICT); class c { function test($a) {} } class cc extends c { function test() {} } Don't worry though, it's ["not a bug"](https://bugs.php.net/bug.php?id=46851).<|eost|><|sor|>According to the bug report you linked, if you define the classes in the right order, the definition happens at compile time and thus the warning is emitted at compile time. But `error_reporting(E_ALL | E_STRICT);` is a runtime statement and therefore you haven't enabled strict errors yet at the time of the warning.<|eor|><|eoss|><|endoftext|>
15
lolphp
nyamsprod
27vvu1
<|sols|><|sot|>Can someone explain this ?<|eot|><|sol|>http://3v4l.org/WZeAI<|eol|><|eols|><|endoftext|>
22
lolphp
merreborn
ci50uiy
<|sols|><|sot|>Can someone explain this ?<|eot|><|sol|>http://3v4l.org/WZeAI<|eol|><|sor|>all non-numeric strings == 0 (int)'UNLOCK' == (int)0<|eor|><|eols|><|endoftext|>
16
lolphp
gearvOsh
ci4yvic
<|sols|><|sot|>Can someone explain this ?<|eot|><|sol|>http://3v4l.org/WZeAI<|eol|><|sor|>[removed]<|eor|><|sor|>What does a constant have to do with this? There isn't one in the example.<|eor|><|eols|><|endoftext|>
8
lolphp
sloat
1wdk4h
<|sols|><|sot|>"If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass."<|eot|><|sol|>http://www.php.net/manual/en/function.var-export.php#113962<|eol|><|eols|><|endoftext|>
23
lolphp
Deranged40
cf12c7u
<|sols|><|sot|>"If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass."<|eot|><|sol|>http://www.php.net/manual/en/function.var-export.php#113962<|eol|><|sor|>> So I wrote an improved_var_export() Fuck fixing it. just write a better one. MOAR FUNCTIONS! <|eor|><|eols|><|endoftext|>
25
lolphp
allthediamonds
cf154q4
<|sols|><|sot|>"If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass."<|eot|><|sol|>http://www.php.net/manual/en/function.var-export.php#113962<|eol|><|sor|>> So I wrote an improved_var_export() Fuck fixing it. just write a better one. MOAR FUNCTIONS! <|eor|><|sor|>I love how PHP empowers programmers to half-assedly fix their own broken language. I call it Rasmusism: if it works [on my machine] don't fix it<|eor|><|eols|><|endoftext|>
20
lolphp
_sgtk
cf18v6l
<|sols|><|sot|>"If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass."<|eot|><|sol|>http://www.php.net/manual/en/function.var-export.php#113962<|eol|><|sor|>For the sake of consistency, (s)he should've named it var_real_export(). Unless it was for the consistency of inconsistency.<|eor|><|eols|><|endoftext|>
13
lolphp
poizan42
cf21iks
<|sols|><|sot|>"If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass."<|eot|><|sol|>http://www.php.net/manual/en/function.var-export.php#113962<|eol|><|sor|>...and? It doesn't work for any class which doesn't. What is the "lolphp" here? Shouldn't it be a good thing that PHP won't let you use var_export on a class unless it was made to be exportable, preventing exporting of classes which couldn't be imported properly?<|eor|><|sor|>Well you can still serialize()/unserialize() it, you just can't serialize it to the valid-php-plaintext form used by var_export()...<|eor|><|eols|><|endoftext|>
5
lolphp
neoform
1nq2n1
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|eoss|><|endoftext|>
22
lolphp
ANAL_GRAVY
ccl7i2r
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>There actually might be a reason for this. The JSON library is under a weird licence, so much so that Google [are trying to avoid it](http://wonko.com/post/jsmin-isnt-welcome-on-google-code) (a really good read). There's even a [bug report for PHP](https://bugs.php.net/bug.php?id=63520) for it. The line in the license? The Software shall be used for Good, not Evil. ^((Though I agree, it's bloody stupid to not use the library. What happened to proper escaping?)^)<|eor|><|eoss|><|endoftext|>
24
lolphp
neoform
ccl40vb
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>It's an example. Pretty sure you are supposed to use your brain along with the API.<|eor|><|soopr|>Examples should not be using flawed/buggy code.<|eoopr|><|eoss|><|endoftext|>
18
lolphp
steamruler
cclh62t
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>There actually might be a reason for this. The JSON library is under a weird licence, so much so that Google [are trying to avoid it](http://wonko.com/post/jsmin-isnt-welcome-on-google-code) (a really good read). There's even a [bug report for PHP](https://bugs.php.net/bug.php?id=63520) for it. The line in the license? The Software shall be used for Good, not Evil. ^((Though I agree, it's bloody stupid to not use the library. What happened to proper escaping?)^)<|eor|><|sor|>>I give permission for IBM, its customers, partners, and minions, to use JSLint for evil. Fuck, now I have coffee all over my desk.<|eor|><|eoss|><|endoftext|>
15
lolphp
mirhagk
ccmhvrl
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>There actually might be a reason for this. The JSON library is under a weird licence, so much so that Google [are trying to avoid it](http://wonko.com/post/jsmin-isnt-welcome-on-google-code) (a really good read). There's even a [bug report for PHP](https://bugs.php.net/bug.php?id=63520) for it. The line in the license? The Software shall be used for Good, not Evil. ^((Though I agree, it's bloody stupid to not use the library. What happened to proper escaping?)^)<|eor|><|sor|>The guy basically took the MIT license, and prevented any major players from using the library (since the license would NOT hold up in court, and could have very serious ramifications for any company that used the software). The whole point of the MIT was to be truly free, to allow anyone to use it for anything, and then he went ahead and basically said "use this library, unless you're a large corporation with real fears of being sued"<|eor|><|eoss|><|endoftext|>
10
lolphp
maxufimo
cckzke7
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>Gotta love the anchor in the link though: `#booya`<|eor|><|eoss|><|endoftext|>
8
lolphp
Porges
ccl6hon
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>It's an example. Pretty sure you are supposed to use your brain along with the API.<|eor|><|soopr|>Examples should not be using flawed/buggy code.<|eoopr|><|sor|>Yo MSDN, do you hear this?<|eor|><|eoss|><|endoftext|>
7
lolphp
Ipswitch84
ccl7bow
<|soss|><|sot|>Google Analytics in PHP Examples<|eot|><|sost|>https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#booya function getTransactionJs(&$trans) { return <<<HTML ga('ecommerce:addTransaction', { 'id': '{$trans['id']}', 'affiliation': '{$trans['affiliation']}', 'revenue': '{$trans['revenue']}', 'shipping': '{$trans['shipping']}', 'tax': '{$trans['tax']}' }); HTML; } Apparently Google has never heard of escaping content, nor have their heard of ```json_encode()```.<|eost|><|sor|>I've discovered that most 3rd party vendors can't write PHP libraries unless their primary business language is PHP and even then it can be a crapshoot. Google seems to be one of the worst offenders.<|eor|><|eoss|><|endoftext|>
6
lolphp
Kwpolska
1gx0gr
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|eols|><|endoftext|>
24
lolphp
afraca
caoue0n
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|sor|>To me this seems as sort of a good thing, or am I missing something here? The syntax is similar to that of python. <|eor|><|eols|><|endoftext|>
12
lolphp
philsturgeon
cazyur4
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|sor|>To me this seems as sort of a good thing, or am I missing something here? The syntax is similar to that of python. <|eor|><|soopr|>Everyone and their mom had generators for ages. PHP does this since Thursday (trunk doesnt matter). This is the laughing matter.<|eoopr|><|sor|>You can't complain about something being missing, then complain about it being implemented. That's just being silly.<|eor|><|eols|><|endoftext|>
7
lolphp
ealf
cate4dk
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|sor|>> If you use yield in an expression context (for example, on the right hand side of an assignment), you must surround the yield statement with parentheses. For example, this is valid: `$data = (yield $value);` > But this is not, and will result in a parse error: `$data = yield $value;` <|eor|><|eols|><|endoftext|>
6
lolphp
Liorithiel
caow8eb
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|sor|>To me this seems as sort of a good thing, or am I missing something here? The syntax is similar to that of python. <|eor|><|sor|>Probably the numbers. My installation of python (64-bit) takes 32MB of memory to keep a list of million integers (which is already kinda quite a lot, but that's the price you pay for a dynamic type system and a data structure that allows mixing types), but still not well over 100MB. Also, the `xrange` operator takes 40 byteswe don't know what less than 1 kilobyte means, but it still suggests something an order of magnitude bigger. But yes, generators in php? Good thing.<|eor|><|eols|><|endoftext|>
5
lolphp
nikic
capqinr
<|sols|><|sot|>PHP 5.5.0 brings generators with good syntax!<|eot|><|sol|>http://php.net/manual/en/language.generators.overview.php<|eol|><|sor|>To me this seems as sort of a good thing, or am I missing something here? The syntax is similar to that of python. <|eor|><|sor|>Probably the numbers. My installation of python (64-bit) takes 32MB of memory to keep a list of million integers (which is already kinda quite a lot, but that's the price you pay for a dynamic type system and a data structure that allows mixing types), but still not well over 100MB. Also, the `xrange` operator takes 40 byteswe don't know what less than 1 kilobyte means, but it still suggests something an order of magnitude bigger. But yes, generators in php? Good thing.<|eor|><|sor|>PHP has no dedicated type for continuously indexed arrays. It always uses an ordered dictionary. As such there is a lot more overhead ;)<|eor|><|eols|><|endoftext|>
5
lolphp
isotopp
1bx54o
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|eoss|><|endoftext|>
21
lolphp
midir
c9ay85x
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|sor|>To state it more plainly: var_dump(min(-23, true)); // int(-23) var_dump(min(true, -23)); // bool(true) Apparently this is a feature of boolean to number comparisons. They seem to always return false, causing min to always return the first argument.<|eor|><|eoss|><|endoftext|>
24
lolphp
farsightxr20
c9b2fgf
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|eoss|><|endoftext|>
22
lolphp
Porges
c9b906k
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|sor|>PHP: The Principle of Most Surprise<|eor|><|eoss|><|endoftext|>
19
lolphp
farsightxr20
c9bca0o
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|sor|>Why would it? The main feature of PHP is dynamic typing. I'd say the WTF is the developer using a boolean for a function that deals with integers.<|eor|><|sor|>> The main feature of PHP is **weak** dynamic typing. Python and Ruby have dynamic typing too, but they have strong dynamic typing (ie. all conversions are explicit).<|eor|><|eoss|><|endoftext|>
13
lolphp
vytah
c9b63f1
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|sor|>It's PHP. Instead of an exception, it would rather return False.<|eor|><|eoss|><|endoftext|>
10
lolphp
Packet_Ranger
c9b5w64
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|eoss|><|endoftext|>
9
lolphp
isotopp
c9awf3i
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|eoss|><|endoftext|>
8
lolphp
catcradle5
c9bat11
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|sor|>Why would it? The main feature of PHP is dynamic typing. I'd say the WTF is the developer using a boolean for a function that deals with integers.<|eor|><|sor|>Here's the thing. A lot of the people who defend PHP, including some of its core developers, will say "no sane developer would do this anyway, so this is a non-issue." And in many cases they will close bug reports because of this. The problem is, the fact that behavior like this even occurs *at all* shows the natural flaws in the language's design. Some weird combinations can even produce segfaults, and even those bug reports are closed because the developer "is not following the standards." A language is supposed to be robust and consistent. If it isn't, even in the face of a dumb developer, then it is the language that is at fault.<|eor|><|eoss|><|endoftext|>
7
lolphp
nikic
c9c7smw
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|sor|>To state it more plainly: var_dump(min(-23, true)); // int(-23) var_dump(min(true, -23)); // bool(true) Apparently this is a feature of boolean to number comparisons. They seem to always return false, causing min to always return the first argument.<|eor|><|sor|>Am I the only one here who thinks this makes sense? `true` and `-23` are not orderable (so both `true > -23` and `true < -23` are `false`). Thus their order is undefined. The undefined behavior here manifests by returning the first element (though it could just as well be the last).<|eor|><|eoss|><|endoftext|>
6
lolphp
mirhagk
c9b4fbb
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|sor|>To state it more plainly: var_dump(min(-23, true)); // int(-23) var_dump(min(true, -23)); // bool(true) Apparently this is a feature of boolean to number comparisons. They seem to always return false, causing min to always return the first argument.<|eor|><|sor|>Ummm... wouldn't it make more sense to cast the boolean to a number.... ie true==1 and false ==0, so false<true and true<2. This would give consistent behaviour. And since true = 1 and false = 0, it can safely return the casted boolean which would be treated correctly. Then again, this is PHP.<|eor|><|eoss|><|endoftext|>
6
lolphp
catcradle5
c9bc4kn
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|soopr|>See also http://www.php.net/manual/de/function.min.php#65516<|eoopr|><|sor|>> NEVER EVER use this function with boolean variables !!! I think the fact that this even needs to be stated is deserving of a lolphp community award in itself.<|eor|><|sor|>TRWTF is that it returns instead of raising an exception. <|eor|><|sor|>Why would it? The main feature of PHP is dynamic typing. I'd say the WTF is the developer using a boolean for a function that deals with integers.<|eor|><|sor|>Here's the thing. A lot of the people who defend PHP, including some of its core developers, will say "no sane developer would do this anyway, so this is a non-issue." And in many cases they will close bug reports because of this. The problem is, the fact that behavior like this even occurs *at all* shows the natural flaws in the language's design. Some weird combinations can even produce segfaults, and even those bug reports are closed because the developer "is not following the standards." A language is supposed to be robust and consistent. If it isn't, even in the face of a dumb developer, then it is the language that is at fault.<|eor|><|sor|>The bigger problem is type casting. Even with Python, a language designed better than PHP, this same problem persists. The output is nearly identical to PHPs. Throwing exceptions or errors goes against what a dynamically typed language should do.<|eor|><|sor|>Nope! I even tested it in Python before I made my first comment. Python output: `min(-23, True)` -> `-23` `min(True, -23)` -> `-23` If it were broken like PHP, the first would've output either `True` or `1`. The problem with the PHP in OP's example isn't implicit casting.<|eor|><|eoss|><|endoftext|>
6
lolphp
midir
c9cl0an
<|soss|><|sot|>MIN<|eot|><|sost|> server:~ # php -r 'echo True, " ", -23, " ", min(-23, True), " ", min(True, -23), "\n";' 1 -23 -23 1 <|eost|><|sor|>To state it more plainly: var_dump(min(-23, true)); // int(-23) var_dump(min(true, -23)); // bool(true) Apparently this is a feature of boolean to number comparisons. They seem to always return false, causing min to always return the first argument.<|eor|><|sor|>Am I the only one here who thinks this makes sense? `true` and `-23` are not orderable (so both `true > -23` and `true < -23` are `false`). Thus their order is undefined. The undefined behavior here manifests by returning the first element (though it could just as well be the last).<|eor|><|sor|>Well there's no ideal thing to do, but it is a bit ugly that `min(a, b) != min(b, a)`. But since they're not orderable, raising a notice would be an alternative. Or make them orderable by coercing true to 1 (as is done for arithmetic like `-23+true`). It probably wouldn't be changed though. Loose typing inevitably has awkward edge cases like this.<|eor|><|eoss|><|endoftext|>
5
lolphp
Altreus
w9wpa
<|soss|><|sot|>Came across this compile-time fun today<|eot|><|sost|>As we all know, many languages allow you to use the boolean operators to do a shorthand if-type construct: do() or die(); PHP is the same. EXPR or EXPR generally works, as does EXPR and EXPR. The problem is that the RHS of these expressions apparently has to conform to certain criteria, one of which is that the expression returns something. [citation needed] because that's currently my best guess. PHP has no concept of not returning something. Functions always return null if they don't explicitly return something else. Except built-in functions can return void. This appears to be implemented at compile time by it being a syntax error to use it in any non-void context. echo is one such function: $cats = echo "Cats!"; Parse error: syntax error, unexpected 'echo' (T_ECHO) in ... Except that's not true because die (exit) is void and that compiles fine: $cats = die("Cats!"); This dies. The upshot here is that you can't use anything that doesn't return as the RHS expression of and/or. For this reason, presumably, PHP's print returns 1. $cats = print "Cats!"; print $cats; # 1 Presumably its returning 1 means it can return 0 on error? NOPE This function, which isn't a function, always returns 1. Presumably if PHP can't print it dies horrifically but actually I would expect that what actually happens is it continues without even mentioning it, like with most of its errors. Anyway that means you can do this-- $cats and print "I has cats"; but not this-- $cats and echo "I has cats"; You can do this-- $input or die("No input"); but you can't do this-- $input or throw new Exception("Input required"); The mind surely boggles about how many expressions aren't expressions and how many runtime errors can be compile-time but surely it's not going to break any code to remove voidness of functions/language constructs and start treating expressions like actual sodding expressions? Note that you can do this-- function fthrow($e) { throw $e; } $input or fthrow(new Exception("Input required")); as long as you're not allergic to parens.<|eost|><|eoss|><|endoftext|>
25
lolphp
vytah
c5bq5gm
<|soss|><|sot|>Came across this compile-time fun today<|eot|><|sost|>As we all know, many languages allow you to use the boolean operators to do a shorthand if-type construct: do() or die(); PHP is the same. EXPR or EXPR generally works, as does EXPR and EXPR. The problem is that the RHS of these expressions apparently has to conform to certain criteria, one of which is that the expression returns something. [citation needed] because that's currently my best guess. PHP has no concept of not returning something. Functions always return null if they don't explicitly return something else. Except built-in functions can return void. This appears to be implemented at compile time by it being a syntax error to use it in any non-void context. echo is one such function: $cats = echo "Cats!"; Parse error: syntax error, unexpected 'echo' (T_ECHO) in ... Except that's not true because die (exit) is void and that compiles fine: $cats = die("Cats!"); This dies. The upshot here is that you can't use anything that doesn't return as the RHS expression of and/or. For this reason, presumably, PHP's print returns 1. $cats = print "Cats!"; print $cats; # 1 Presumably its returning 1 means it can return 0 on error? NOPE This function, which isn't a function, always returns 1. Presumably if PHP can't print it dies horrifically but actually I would expect that what actually happens is it continues without even mentioning it, like with most of its errors. Anyway that means you can do this-- $cats and print "I has cats"; but not this-- $cats and echo "I has cats"; You can do this-- $input or die("No input"); but you can't do this-- $input or throw new Exception("Input required"); The mind surely boggles about how many expressions aren't expressions and how many runtime errors can be compile-time but surely it's not going to break any code to remove voidness of functions/language constructs and start treating expressions like actual sodding expressions? Note that you can do this-- function fthrow($e) { throw $e; } $input or fthrow(new Exception("Input required")); as long as you're not allergic to parens.<|eost|><|sor|>It seems like PHP distinguishes between statements and expressions, like many other programming languages. The following Python snippets won't run either: somefunction() or raise Exception() somefunction() or print "Error" The real WTF here is PHP's `print` being a magical operator. But that's nothing inherently bad.<|eor|><|eoss|><|endoftext|>
10
lolphp
more_exercise
c5cyo2f
<|soss|><|sot|>Came across this compile-time fun today<|eot|><|sost|>As we all know, many languages allow you to use the boolean operators to do a shorthand if-type construct: do() or die(); PHP is the same. EXPR or EXPR generally works, as does EXPR and EXPR. The problem is that the RHS of these expressions apparently has to conform to certain criteria, one of which is that the expression returns something. [citation needed] because that's currently my best guess. PHP has no concept of not returning something. Functions always return null if they don't explicitly return something else. Except built-in functions can return void. This appears to be implemented at compile time by it being a syntax error to use it in any non-void context. echo is one such function: $cats = echo "Cats!"; Parse error: syntax error, unexpected 'echo' (T_ECHO) in ... Except that's not true because die (exit) is void and that compiles fine: $cats = die("Cats!"); This dies. The upshot here is that you can't use anything that doesn't return as the RHS expression of and/or. For this reason, presumably, PHP's print returns 1. $cats = print "Cats!"; print $cats; # 1 Presumably its returning 1 means it can return 0 on error? NOPE This function, which isn't a function, always returns 1. Presumably if PHP can't print it dies horrifically but actually I would expect that what actually happens is it continues without even mentioning it, like with most of its errors. Anyway that means you can do this-- $cats and print "I has cats"; but not this-- $cats and echo "I has cats"; You can do this-- $input or die("No input"); but you can't do this-- $input or throw new Exception("Input required"); The mind surely boggles about how many expressions aren't expressions and how many runtime errors can be compile-time but surely it's not going to break any code to remove voidness of functions/language constructs and start treating expressions like actual sodding expressions? Note that you can do this-- function fthrow($e) { throw $e; } $input or fthrow(new Exception("Input required")); as long as you're not allergic to parens.<|eost|><|sor|>My ignorance may be showing (I stopped writing PHP long before I ran into exceptions), but why should `throw new Exception()` work there? Isn't that a statement, not an expression?<|eor|><|soopr|>Statements are made out of one or more expressions. I would expect `throw` to be an expression, usually used in a void context. The pattern is (should be) not much different from `die()`, which is the same thing - an expression that can be used as a full statement.<|eoopr|><|sor|>`throw` is (should be) a little different than `die` though - `die` appears to be a function, and like all functions, invoking it is an expression. In constrast, `throw` is a statement, controlling flow - there is no return value from a throw, but instead control leaves the current frame, to appear elsewhere. That said, my naive implementation of `die` would end with a `throw`, to kick out of whereever `die` was invoked. This doesn't make `die` less of an expression, but by virtue of evaluating it, an exception occurs. Statements _can_ be one or more expressions, but there is no requirement (in c-like languages) that a statement contains an expression. Consider `break;`, `continue;`, or (I think in php) even `;`.<|eor|><|soopr|>Sure But wouldn't `$foo or break;` be nice to be able to write? `$foo or continue;`, `$foo or die;`, `$foo or throw ...`, `$foo or goto bar;` ... there's no reason it _can't_ be an expression, or at least some superset of expression that also covers this behaviour.<|eoopr|><|sor|>Perl does this correctly. <|eor|><|sor|>That's because somebody actually put thought into perl<|eor|><|eoss|><|endoftext|>
5
lolphp
ezzatron
rj9o7
<|sols|><|sot|>5.3.9 adds $allow_string to is_a() and is_subclass_of(), breaks BC just 'cause, and uses $allow_string to control autoloading... _<|eot|><|sol|>http://php.net/manual/en/function.is-a.php<|eol|><|eols|><|endoftext|>
21
lolphp
farsightxr20
c46ajth
<|sols|><|sot|>5.3.9 adds $allow_string to is_a() and is_subclass_of(), breaks BC just 'cause, and uses $allow_string to control autoloading... _<|eot|><|sol|>http://php.net/manual/en/function.is-a.php<|eol|><|sor|>Lol, all they had to do to preserve BC was default it to true instead of false.<|eor|><|eols|><|endoftext|>
10
lolphp
petdance
pi6wv
<|sols|><|sot|>To encode special characters, use htmlentities(). To decode, use html_entity_decode(). Who needs orthogonality?<|eot|><|sol|>http://www.php.net/manual/en/function.htmlentities.php<|eol|><|eols|><|endoftext|>
23
lolphp
Rhomboid
c3ponav
<|sols|><|sot|>To encode special characters, use htmlentities(). To decode, use html_entity_decode(). Who needs orthogonality?<|eot|><|sol|>http://www.php.net/manual/en/function.htmlentities.php<|eol|><|sor|>The default charset for `htmlentities` wasn't UTF-8 until 5.4, so the shortest way to do it *right* without corrupting the output by encoding each byte of a character separately was `htmlspecialchars()`. For those of you following at home, yes, that's a 16-char function name to do the most basic operation in a website scripting language. (I realise that's a non-issue for most PHP scripters because unicode-aware PHP users are a tiny minority)<|eor|><|sor|>Here's my impression of a PHP developer: LOL unicode? Whats that shit? LOLOL u shouldn't be using those letters computers can't represent dem <|eor|><|eols|><|endoftext|>
18
lolphp
gearvOsh
c3pptst
<|sols|><|sot|>To encode special characters, use htmlentities(). To decode, use html_entity_decode(). Who needs orthogonality?<|eot|><|sol|>http://www.php.net/manual/en/function.htmlentities.php<|eol|><|soopr|>Never mind orthogonality, I'd settle for consistent use of underscores.<|eoopr|><|sor|>On top of that, I would consistency between "verb_noun" and "noun_verb" functions. http://us2.php.net/manual-lookup.php?pattern=create&scope=quickref Would like namespaced objects in PHP 6 instead of this giant pool of functions.<|eor|><|eols|><|endoftext|>
8
lolphp
petdance
c3pjyvn
<|sols|><|sot|>To encode special characters, use htmlentities(). To decode, use html_entity_decode(). Who needs orthogonality?<|eot|><|sol|>http://www.php.net/manual/en/function.htmlentities.php<|eol|><|soopr|>Never mind orthogonality, I'd settle for consistent use of underscores.<|eoopr|><|eols|><|endoftext|>
7
lolphp
annoymind
k1age
<|sols|><|sot|>This is a tale of an integer overflow vulnerability in PHP.<|eot|><|sol|>http://use.perl.org/~Aristotle/journal/33448<|eol|><|eols|><|endoftext|>
24
lolphp
Rhomboid
c2gyjot
<|sols|><|sot|>This is a tale of an integer overflow vulnerability in PHP.<|eot|><|sol|>http://use.perl.org/~Aristotle/journal/33448<|eol|><|sor|>`sizeof(char)` is 1 by definition on every platform, regardless of how many actual bits are in a char. That must have been a comedic flourish, as I struggle to believe that someone would write that. <|eor|><|eols|><|endoftext|>
11
lolphp
Takeoded
j8ql4s
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|eoss|><|endoftext|>
24
lolphp
elcapitanoooo
g8dke1m
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|eoss|><|endoftext|>
12
lolphp
Perdouille
g8d1swj
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>It has been integrated into the language in 5.1, but it exists as a PECL package since 2005 and is compatlble PHP 4 https://pecl.php.net/package/hash<|eor|><|eoss|><|endoftext|>
10
lolphp
Takeoded
g8eja2y
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|soopr|>speaking of namespaces, WHY THE F**K are variables created inside namespaces put in the global namespace, not tied to the namespace they were created in? (whilst functions and classes are actually tied to the namespace they're created in)<|eoopr|><|eoss|><|endoftext|>
9
lolphp
smegnose
g8fpbdo
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|sor|>The buckets were by the string length of the function name. This is why underscore usage in core function names is inconsistent, even in related functions.<|eor|><|eoss|><|endoftext|>
8
lolphp
Takeoded
g8de1x7
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>It has been integrated into the language in 5.1, but it exists as a PECL package since 2005 and is compatlble PHP 4 https://pecl.php.net/package/hash<|eor|><|soopr|>so likely it integrated that way `to stay compatible with the PECL version`, then i guess? good to know, still wish they'd do something about it (like they did with mysqli perhaps? mysqli has both an OO api and a procedural api, ref https://www.php.net/manual/en/mysqli.query.php )<|eoopr|><|eoss|><|endoftext|>
6
lolphp
elcapitanoooo
g8g6ssn
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|soopr|>speaking of namespaces, WHY THE F**K are variables created inside namespaces put in the global namespace, not tied to the namespace they were created in? (whilst functions and classes are actually tied to the namespace they're created in)<|eoopr|><|sor|>I guess its because the namespace fiasco was just put together like drunk sailors in a brothel. There was no plan, there was no design with things that already existed. PHP had a great opportunity to create a new core namespace and have actual OOP methods for core stuff (dont know why php wanted to even go with java-like OOP in the first place?) and then later deprecate all the old global crap. Instead they added more and more to the global "namespace" each year. Instead of focusing on important things, like unicode support (PHP is a web language so you would assume unicode was high on their list) they focus on irrelevant things like adding goto traits support for classes. Now the focus seem to be on a "typesystem" but i have very low hopes for this, and it seems to be a new lol all together. PHP is not only dynamic, but also clusterfuckedly typed, so many weird coercions going on no type system can manage that crap. Im guessing the next big release will have PHP generics, then we have gone full circle in the circus. Dont know how much time PHP devs put on performance, but as i see it its also a lost cause. PHP is rarely about CPU bound tasks, and all about IO, this IO cant be optimised in PHP. So this is why most benchmarks also places PHP in the bottom. Core PHP is start + die immediately. This makes it real hard to do real optimisation and also makes some trivial apps impossible to create in php.<|eor|><|eoss|><|endoftext|>
6
lolphp
Takeoded
g8gdyq0
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|soopr|>speaking of namespaces, WHY THE F**K are variables created inside namespaces put in the global namespace, not tied to the namespace they were created in? (whilst functions and classes are actually tied to the namespace they're created in)<|eoopr|><|sor|>I guess its because the namespace fiasco was just put together like drunk sailors in a brothel. There was no plan, there was no design with things that already existed. PHP had a great opportunity to create a new core namespace and have actual OOP methods for core stuff (dont know why php wanted to even go with java-like OOP in the first place?) and then later deprecate all the old global crap. Instead they added more and more to the global "namespace" each year. Instead of focusing on important things, like unicode support (PHP is a web language so you would assume unicode was high on their list) they focus on irrelevant things like adding goto traits support for classes. Now the focus seem to be on a "typesystem" but i have very low hopes for this, and it seems to be a new lol all together. PHP is not only dynamic, but also clusterfuckedly typed, so many weird coercions going on no type system can manage that crap. Im guessing the next big release will have PHP generics, then we have gone full circle in the circus. Dont know how much time PHP devs put on performance, but as i see it its also a lost cause. PHP is rarely about CPU bound tasks, and all about IO, this IO cant be optimised in PHP. So this is why most benchmarks also places PHP in the bottom. Core PHP is start + die immediately. This makes it real hard to do real optimisation and also makes some trivial apps impossible to create in php.<|eor|><|soopr|>> Instead of focusing on important things, like unicode support actually they tried, and failed. native unicode support was what PHP6 was all about, but the performance/memory impact was significant (going from byte-strings to UTF16 strings was it?), and "a lack of developers who understood what was needed" and stuff.. anyway they failed, and abandoned php6 altogether. > Dont know how much time PHP devs put on performance \*a lot\*. Php has had a significant lead over Python in the benchmark games ever since the PHP5 days, the PHP7 release was another significant speed increase (php7 data structures were optimized to be cpu-cache friendly, unlike php5.x~), and PHP8's new JIT/AOT native-code compiler should give yet another significant speed increase. check https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php-python3.html , and that's no coincidence (the PHP core devs really care about performance, and it shows.) > this IO cant be optimised in PHP that's not quite true, file_get_contents() is using mmap() memory-mapping to read files when possible, and in php5.3 the PHP team threw out libmysqlclient and made their own mysql client library to talk faster with MySQL than what's possible using libmysqlclient (for example with libmysqlclient there is data it fetches from mysql, then it makes A COPY of that data and sends the copy to the library's user. by throwing out libmysqlclient and making their own client library, they were able to avoid this data copying, resulting in fewer malloc()'s, fewer memcpy()'s, and faster mysql IO overall) funfact: PHP talks faster to MySQL than Google's Go programming language. I bet that's because Go is using libmysqlclient, and PHP is using their own homemade client<|eoopr|><|eoss|><|endoftext|>
6
lolphp
elcapitanoooo
g8gtp8d
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|soopr|>speaking of namespaces, WHY THE F**K are variables created inside namespaces put in the global namespace, not tied to the namespace they were created in? (whilst functions and classes are actually tied to the namespace they're created in)<|eoopr|><|sor|>I guess its because the namespace fiasco was just put together like drunk sailors in a brothel. There was no plan, there was no design with things that already existed. PHP had a great opportunity to create a new core namespace and have actual OOP methods for core stuff (dont know why php wanted to even go with java-like OOP in the first place?) and then later deprecate all the old global crap. Instead they added more and more to the global "namespace" each year. Instead of focusing on important things, like unicode support (PHP is a web language so you would assume unicode was high on their list) they focus on irrelevant things like adding goto traits support for classes. Now the focus seem to be on a "typesystem" but i have very low hopes for this, and it seems to be a new lol all together. PHP is not only dynamic, but also clusterfuckedly typed, so many weird coercions going on no type system can manage that crap. Im guessing the next big release will have PHP generics, then we have gone full circle in the circus. Dont know how much time PHP devs put on performance, but as i see it its also a lost cause. PHP is rarely about CPU bound tasks, and all about IO, this IO cant be optimised in PHP. So this is why most benchmarks also places PHP in the bottom. Core PHP is start + die immediately. This makes it real hard to do real optimisation and also makes some trivial apps impossible to create in php.<|eor|><|soopr|>> Instead of focusing on important things, like unicode support actually they tried, and failed. native unicode support was what PHP6 was all about, but the performance/memory impact was significant (going from byte-strings to UTF16 strings was it?), and "a lack of developers who understood what was needed" and stuff.. anyway they failed, and abandoned php6 altogether. > Dont know how much time PHP devs put on performance \*a lot\*. Php has had a significant lead over Python in the benchmark games ever since the PHP5 days, the PHP7 release was another significant speed increase (php7 data structures were optimized to be cpu-cache friendly, unlike php5.x~), and PHP8's new JIT/AOT native-code compiler should give yet another significant speed increase. check https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php-python3.html , and that's no coincidence (the PHP core devs really care about performance, and it shows.) > this IO cant be optimised in PHP that's not quite true, file_get_contents() is using mmap() memory-mapping to read files when possible, and in php5.3 the PHP team threw out libmysqlclient and made their own mysql client library to talk faster with MySQL than what's possible using libmysqlclient (for example with libmysqlclient there is data it fetches from mysql, then it makes A COPY of that data and sends the copy to the library's user. by throwing out libmysqlclient and making their own client library, they were able to avoid this data copying, resulting in fewer malloc()'s, fewer memcpy()'s, and faster mysql IO overall) funfact: PHP talks faster to MySQL than Google's Go programming language. I bet that's because Go is using libmysqlclient, and PHP is using their own homemade client<|eoopr|><|sor|>Well, its funny as PHP is faster than python, still python is used as glue for all heavy AI and ML calculations, numpy and others are really fast, probably by orders of magnitude. Granted they are written i highy optimised C and fortran as they should. PHP cpu speed, as in math-y benchmarks are irrelevant for the PHP app space. What PHP needs is high thru-put for apps like wordpress and cms systems. Benchmarks in this category (were 99% of php is used) are the ones you should be looking at.<|eor|><|soopr|>> PHP cpu speed, as in math-y benchmarks are irrelevant for the PHP app space i kindof disagree, at my work we're serving anywhere between 700-1200 http requests EVERY FUCKING SECOND 24/7 using php, right now as of writing, its 742 requests this very second. it's hosted on AWS, and we get billed for PHP's cpu usage (also other things ofc, but the CPU usage is a significant part of the bill, and its over 4000USD/month, we expect the cpu-part of the bill to go down with the PHP8 release. and if we switched it to Python, i would expect the CPU part of the bill to go significantly UP! - personally i suggested rewriting the important parts in C++, but the CTO denied it, because there's only 2 devs in the whole company that actually knows C++, another dev wanted to rewrite it in Rust, but there's only 1 Rust dev in the whole company) > What PHP needs is high thru-put for apps like wordpress and cms systems yeah, php's homemade mysql client helps in that department, but one big issue here is that the whole WP engine needs to be started on every request with php's "every request is a clean slate" design.. php-fpm's "every child worker handles 1000 (configurable) requests before committing suicide" helps a little, but it was mostly fixed in PHP7.4+php-fpm, which introduced [OPCache Preloading](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.preload) which allows the entire WP engine to be pre-loaded in every php request (now the wp engine only needs to be initialized once every 1000 requests (configurable) instead of every request) - but setting up opcache preloading properly is also a lot of work, sooo most people won't bother, i bet. (hell, most people don't even run 7.4 yet)<|eoopr|><|sor|> Hmmm dont know what your app does, but 1200 request per second that dont do IO and only CPU heavy stuff just screams please rewrite me in compiled language please<|eor|><|eoss|><|endoftext|>
6
lolphp
elcapitanoooo
g8g5wok
<|soss|><|sot|>hash_init() & co is a clusterfuck<|eot|><|sost|>here is what a sensible hash_init() implementation would look like: ```php class HashContenxt{ public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL); public function update(string $data):void; public function update_file(string $file):void; public function update_stream($handle):void; public function final():string; } ``` - but what did the PHP developers do instead? they created a class in the global namespace which seems to serve no purpose whatsoever (HashContext), and created 5 functions in the global namespace, and created 1 constant in the global namespace. Why? i have no idea, it's not like they didn't have a capable class system by the time of hash_init()'s introduction (hash_init() was implemented in 5.1.2, sure USERLAND code couldn't introduce class constants at that time, but php-builtin classes could, ref the PDO:: constants introduced in 5.1.0)<|eost|><|sor|>PHP managed to fuck up scoping 3 times. First when PHP was created, functions were all global and IIRC bucketed by some weird naming convention. Its was all a big mess. Then round 2 when PHP added a namespaces. Personally i had high hopes back then (iirc 5.2 or 5.3?) about finally getting some sanity. What we got was a weird hodge podge of level9 insanity. The final fuckup was in PHP8 when they could have finally deprecated stuff for a hope of a better language. We got more insanity and nothing removed at all. Oh, php 5.4 also added goto<|eor|><|sor|>The buckets were by the string length of the function name. This is why underscore usage in core function names is inconsistent, even in related functions.<|eor|><|sor|>Yes that was it. A real mindbender of its own<|eor|><|eoss|><|endoftext|>
5
lolphp
Mmarco94
692jwj
<|sols|><|sot|>ob_clean resets some headers when the output is buffered<|eot|><|sol|>https://stackoverflow.com/questions/43768383/php-ob-startob-gzhandler-with-ob-clean-error<|eol|><|eols|><|endoftext|>
22
lolphp
Max-P
dh3j1bg
<|sols|><|sot|>ob_clean resets some headers when the output is buffered<|eot|><|sol|>https://stackoverflow.com/questions/43768383/php-ob-startob-gzhandler-with-ob-clean-error<|eol|><|sor|>gzipping the output in PHP alone is pretty lolphpusers too considering every web server out there will do it transparently. Using ob for whole page stuff is asking for trouble.<|eor|><|eols|><|endoftext|>
14
lolphp
the_alias_of_andrea
dh3fgv7
<|sols|><|sot|>ob_clean resets some headers when the output is buffered<|eot|><|sol|>https://stackoverflow.com/questions/43768383/php-ob-startob-gzhandler-with-ob-clean-error<|eol|><|sor|>This looks like a StackOverflow question that should really be a bug report.<|eor|><|eols|><|endoftext|>
10
lolphp
nyamsprod
37caox
<|sols|><|sot|>parse_str behavior is sometimes strange<|eot|><|sol|>http://3v4l.org/23nkR<|eol|><|eols|><|endoftext|>
22
lolphp
weirdasianfaces
crljd4d
<|sols|><|sot|>parse_str behavior is sometimes strange<|eot|><|sol|>http://3v4l.org/23nkR<|eol|><|sor|>Could someone tell me a sane use case for `parse_str`?<|eor|><|sor|>> Parses str as if it were the query string passed via a URL **and sets variables in the current scope**. (if the second parameter `$arr` is not provided, emphasis above is mine). I can see that going terribly, terribly wrong. When would you *ever* want it to magically set variables?!<|eor|><|eols|><|endoftext|>
10
lolphp
profmonocle
crm7cp7
<|sols|><|sot|>parse_str behavior is sometimes strange<|eot|><|sol|>http://3v4l.org/23nkR<|eol|><|sor|>Could someone tell me a sane use case for `parse_str`?<|eor|><|sor|>> Parses str as if it were the query string passed via a URL **and sets variables in the current scope**. (if the second parameter `$arr` is not provided, emphasis above is mine). I can see that going terribly, terribly wrong. When would you *ever* want it to magically set variables?!<|eor|><|sor|>What drives me insane is wondering *why* this function exists as it does. I can only assume a PHP developer thought doing something like this... $arr=parse_string(...); $val1=$arr['val1']; $val2=$arr['val2']; //etc. ...was too much work, and just wanted to be able to do $val1 $val2 $val3 with less code. So they whipped up this dangerous function and made it a permanent feature of the language. But hey, maybe sometimes you *wouldn't* want to let users inject arbitrary values into arbitrary variables, so as an afterthought let's add an argument that massively alters the function's behavior. (And if anyone else was wondering, yes, this function *will* modify already-set variables.)<|eor|><|eols|><|endoftext|>
10
lolphp
weirdasianfaces
crm7ps9
<|sols|><|sot|>parse_str behavior is sometimes strange<|eot|><|sol|>http://3v4l.org/23nkR<|eol|><|sor|>Could someone tell me a sane use case for `parse_str`?<|eor|><|sor|>> Parses str as if it were the query string passed via a URL **and sets variables in the current scope**. (if the second parameter `$arr` is not provided, emphasis above is mine). I can see that going terribly, terribly wrong. When would you *ever* want it to magically set variables?!<|eor|><|sor|>What drives me insane is wondering *why* this function exists as it does. I can only assume a PHP developer thought doing something like this... $arr=parse_string(...); $val1=$arr['val1']; $val2=$arr['val2']; //etc. ...was too much work, and just wanted to be able to do $val1 $val2 $val3 with less code. So they whipped up this dangerous function and made it a permanent feature of the language. But hey, maybe sometimes you *wouldn't* want to let users inject arbitrary values into arbitrary variables, so as an afterthought let's add an argument that massively alters the function's behavior. (And if anyone else was wondering, yes, this function *will* modify already-set variables.)<|eor|><|sor|>> yes, this function will modify already-set variables. I was wondering about that. This seems like a terrible function to use in a security context. With that said I don't know why you would ever use it in a security context to begin with.<|eor|><|eols|><|endoftext|>
6
lolphp
i_make_snow_flakes
2md8c0
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|eoss|><|endoftext|>
23
lolphp
00Davo
cm36h9l
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>C's and C++'s atoi both accept "+1" JavaScript's parseInt accepts "+1" Perl accepts "+1" S/He's violating the principle of least surprise then again, idiotic code for PHP is no surprise either <|eor|><|sor|>`int()` in Python, `.to_i` in Ruby, `string->number` in Scheme, and `tonumber()` in Lua all also accept "+1". It's the sensible thing to do. Which is why PHP's not going to do it.<|eor|><|eoss|><|endoftext|>
26
lolphp
00Davo
cm3rccg
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>C's and C++'s atoi both accept "+1" JavaScript's parseInt accepts "+1" Perl accepts "+1" S/He's violating the principle of least surprise then again, idiotic code for PHP is no surprise either <|eor|><|sor|>`int()` in Python, `.to_i` in Ruby, `string->number` in Scheme, and `tonumber()` in Lua all also accept "+1". It's the sensible thing to do. Which is why PHP's not going to do it.<|eor|><|sor|>And also C#'s `Int32.Parse()`, Obj-C's `intValue` and Pascal's `StrToInt()`. Heck, even SQL(ite)'s `cast()` works. I can't think of any language with reasonable standard libraries that *doesn't* do this.<|eor|><|sor|>Fun fact: I can. In particular, Haskell will throw an exception on `(read "+1") :: Int`. Of course, in Haskell "+1" isn't valid numeric literal syntax, probably because it'd interact oddly with sections `(+1)`. So it makes sense. Ish.<|eor|><|eoss|><|endoftext|>
16
lolphp
Rhomboid
cm3h6pd
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>C's and C++'s atoi both accept "+1" JavaScript's parseInt accepts "+1" Perl accepts "+1" S/He's violating the principle of least surprise then again, idiotic code for PHP is no surprise either <|eor|><|sor|>This isn't atoi or parseInt, it's a lossless-only cast function. Consequently, it accepts a narrower range of input.<|eor|><|sor|>But the proposal already concedes that it's impossible to be lossless in the case of floats (e.g. 1.500 round trips to 1.5, as does 1.50000000000001), so that idea is already broken. Why cling to that for ints when it creates very surprising and unexpected behavior? <|eor|><|eoss|><|endoftext|>
15
lolphp
ElusiveGuy
cm38dmt
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>C's and C++'s atoi both accept "+1" JavaScript's parseInt accepts "+1" Perl accepts "+1" S/He's violating the principle of least surprise then again, idiotic code for PHP is no surprise either <|eor|><|sor|>`int()` in Python, `.to_i` in Ruby, `string->number` in Scheme, and `tonumber()` in Lua all also accept "+1". It's the sensible thing to do. Which is why PHP's not going to do it.<|eor|><|sor|>And also C#'s `Int32.Parse()`, Obj-C's `intValue` and Pascal's `StrToInt()`. Heck, even SQL(ite)'s `cast()` works. I can't think of any language with reasonable standard libraries that *doesn't* do this.<|eor|><|eoss|><|endoftext|>
12
lolphp
i_make_snow_flakes
cm39v3i
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>1. I'm not male. 2. It's a tradeoff. Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves. On the other hand, allowing things like white space and positive signs might make it more useful for some applications. I suppose it depends whether you think losing white space and explicit signs matters. 3. It's not a string parsing function, it's a lossless-only cast function. That's quite an important distinction. It doesn't, and probably shouldn't support things like hexadecimal and octal, whitespace, positive signs or trailing characters. 4. This is an RFC. Anyone with wiki privileges can make an RFC. It's not really fair to complain about proposals that haven't been adopted, are currently under discussion and haven't even been voted on.<|eor|><|soopr|>>I'm not male... Ok. > It's a tradeoff. So you are trading sane behavior for simple internal implementation? I am not getting your point... >Accepting the narrowest possible range of input means you have a much simpler rule +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it? I was mostly baffled by your [this](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm283z2) argument . Do you still maintain it? Or do you think it was flawed? <|eoopr|><|eoss|><|endoftext|>
10
lolphp
i_make_snow_flakes
cm3bggg
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>1. I'm not male. 2. It's a tradeoff. Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves. On the other hand, allowing things like white space and positive signs might make it more useful for some applications. I suppose it depends whether you think losing white space and explicit signs matters. 3. It's not a string parsing function, it's a lossless-only cast function. That's quite an important distinction. It doesn't, and probably shouldn't support things like hexadecimal and octal, whitespace, positive signs or trailing characters. 4. This is an RFC. Anyone with wiki privileges can make an RFC. It's not really fair to complain about proposals that haven't been adopted, are currently under discussion and haven't even been voted on.<|eor|><|soopr|>>I'm not male... Ok. > It's a tradeoff. So you are trading sane behavior for simple internal implementation? I am not getting your point... >Accepting the narrowest possible range of input means you have a much simpler rule +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it? I was mostly baffled by your [this](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm283z2) argument . Do you still maintain it? Or do you think it was flawed? <|eoopr|><|sor|>> So you are trading sane behavior for simple internal implementation? No, implementation-wise it's the same. > +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it. In that case, you'd probably want what ext/filter provides if you're taking form input. This isn't really suited for that use case. > I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed? It's not an argument for this behaviour. It is the principle which leads to this behaviour. <|eor|><|soopr|>>This isn't really suited for that use case. Well, what is the intended use case then..Can you give some examples? <|eoopr|><|eoss|><|endoftext|>
9
lolphp
i_make_snow_flakes
cm3bwyh
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>1. I'm not male. 2. It's a tradeoff. Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves. On the other hand, allowing things like white space and positive signs might make it more useful for some applications. I suppose it depends whether you think losing white space and explicit signs matters. 3. It's not a string parsing function, it's a lossless-only cast function. That's quite an important distinction. It doesn't, and probably shouldn't support things like hexadecimal and octal, whitespace, positive signs or trailing characters. 4. This is an RFC. Anyone with wiki privileges can make an RFC. It's not really fair to complain about proposals that haven't been adopted, are currently under discussion and haven't even been voted on.<|eor|><|soopr|>>I'm not male... Ok. > It's a tradeoff. So you are trading sane behavior for simple internal implementation? I am not getting your point... >Accepting the narrowest possible range of input means you have a much simpler rule +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it? I was mostly baffled by your [this](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm283z2) argument . Do you still maintain it? Or do you think it was flawed? <|eoopr|><|sor|>> So you are trading sane behavior for simple internal implementation? No, implementation-wise it's the same. > +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it. In that case, you'd probably want what ext/filter provides if you're taking form input. This isn't really suited for that use case. > I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed? It's not an argument for this behaviour. It is the principle which leads to this behaviour. <|eor|><|soopr|>>This isn't really suited for that use case. Well, what is the intended use case then..Can you give some examples? <|eoopr|><|sor|>Say you have a site where you have a user profile page that looks up a user by ID: `http://example.com/user.php?id=12` <?php User::get(to_int($_GET['id'])); In this scenario, it doesn't make sense to allow IDs like `%20+012.0%20`.<|eor|><|soopr|>I am not sure I see anything wrong allowing + signs..Even if there was, I am not sure a casting function behavior should be limited or tailored to filtering input values... <|eoopr|><|eoss|><|endoftext|>
9
lolphp
i_make_snow_flakes
cm3cnp0
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>1. I'm not male. 2. It's a tradeoff. Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves. On the other hand, allowing things like white space and positive signs might make it more useful for some applications. I suppose it depends whether you think losing white space and explicit signs matters. 3. It's not a string parsing function, it's a lossless-only cast function. That's quite an important distinction. It doesn't, and probably shouldn't support things like hexadecimal and octal, whitespace, positive signs or trailing characters. 4. This is an RFC. Anyone with wiki privileges can make an RFC. It's not really fair to complain about proposals that haven't been adopted, are currently under discussion and haven't even been voted on.<|eor|><|soopr|>>I'm not male... Ok. > It's a tradeoff. So you are trading sane behavior for simple internal implementation? I am not getting your point... >Accepting the narrowest possible range of input means you have a much simpler rule +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it? I was mostly baffled by your [this](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm283z2) argument . Do you still maintain it? Or do you think it was flawed? <|eoopr|><|sor|>> So you are trading sane behavior for simple internal implementation? No, implementation-wise it's the same. > +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it. In that case, you'd probably want what ext/filter provides if you're taking form input. This isn't really suited for that use case. > I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed? It's not an argument for this behaviour. It is the principle which leads to this behaviour. <|eor|><|soopr|>>This isn't really suited for that use case. Well, what is the intended use case then..Can you give some examples? <|eoopr|><|sor|>Say you have a site where you have a user profile page that looks up a user by ID: `http://example.com/user.php?id=12` <?php User::get(to_int($_GET['id'])); In this scenario, it doesn't make sense to allow IDs like `%20+012.0%20`.<|eor|><|soopr|>I am not sure I see anything wrong allowing + signs..Even if there was, I am not sure a casting function behavior should be limited or tailored to filtering input values... <|eoopr|><|sor|>> limited or tailored to filtering input values What?<|eor|><|soopr|>Just that I think that is not a valid use-case for a casting function...<|eoopr|><|eoss|><|endoftext|>
6
lolphp
i_make_snow_flakes
cm3cyw4
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>> So you are trading sane behavior for simple internal implementation? No, implementation-wise it's the same. > +10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it. In that case, you'd probably want what ext/filter provides if you're taking form input. This isn't really suited for that use case. > I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed? It's not an argument for this behaviour. It is the principle which leads to this behaviour. <|eor|><|soopr|>>This isn't really suited for that use case. Well, what is the intended use case then..Can you give some examples? <|eoopr|><|sor|>Say you have a site where you have a user profile page that looks up a user by ID: `http://example.com/user.php?id=12` <?php User::get(to_int($_GET['id'])); In this scenario, it doesn't make sense to allow IDs like `%20+012.0%20`.<|eor|><|soopr|>I am not sure I see anything wrong allowing + signs..Even if there was, I am not sure a casting function behavior should be limited or tailored to filtering input values... <|eoopr|><|sor|>> limited or tailored to filtering input values What?<|eor|><|soopr|>Just that I think that is not a valid use-case for a casting function...<|eoopr|><|sor|>It's not filtering, it's casting with a measure of validation. This is needed because PHP's current explicit casts (`(int)` etc.) never fail, which is quite dangerous and you can mangle input with them.<|eor|><|soopr|>>it's casting with a measure of validation There. This is what is wrong. It is actually two things but the name says only one, which is casting. And you end up having to implement this weird behavior with respect to the first half (which the name implies), to support the other half of the functionality. And you seem to be down voting me before replying. really?<|eoopr|><|eoss|><|endoftext|>
6
lolphp
i_make_snow_flakes
cm3e01b
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>That's the same thing.<|eor|><|soopr|>No, it's not.<|eoopr|><|sor|>OK, elaborate on what the difference is, then. Fundamentally, no value can't be casted somehow. If something "can't be casted", that means they've chosen not to support a specific type or format of input, or the reverse, chosen only to support a specific type or format.<|eor|><|soopr|>Simple question: is +1 a valid integer in PHP? is the code $a = +1; valid? and will $a have value int(1) after this statement? And are you really down voting me before replying?<|eoopr|><|sor|>> Simple question: is +1 a valid integer in PHP? No. But technically `-1` isn't either. Like most languages, PHP doesn't have signs in its numeric literals. > and will $a have value int(1) after this statement? Yes, because the unary plus (`+`) does nothing.<|eor|><|soopr|>Please take a look [here ](http://php.net/manual/en/language.types.integer.php), under the heading 'Formally, the structure for integer literals is'.. it says decimal : [1-9][0-9]* | 0 integer : [+-]?decimal What does that mean? <|eoopr|><|sor|>The manual is inaccurate, that's not actually how integer literals are defined.<|eor|><|soopr|>Ha ha, this is lolphp right here. it does not matter how it is put in the source code of php. It is the exposed behavior, and the manual says so. Anyway I don't think I want to discuss things with someone who can't respond without down voting every one of my responses. It's not that I care about downvotes, but I find the behavior moronic. So good luck with the RFC.<|eoopr|><|eoss|><|endoftext|>
6
lolphp
ElusiveGuy
cm39ruc
<|soss|><|sot|>new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..<|eot|><|sost|>[here](http://www.reddit.com/r/PHP/comments/2m85jr/rfc_safe_casting_functions_v014/cm24cfr) the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?<|eost|><|sor|>C's and C++'s atoi both accept "+1" JavaScript's parseInt accepts "+1" Perl accepts "+1" S/He's violating the principle of least surprise then again, idiotic code for PHP is no surprise either <|eor|><|sor|>`int()` in Python, `.to_i` in Ruby, `string->number` in Scheme, and `tonumber()` in Lua all also accept "+1". It's the sensible thing to do. Which is why PHP's not going to do it.<|eor|><|sor|>And also C#'s `Int32.Parse()`, Obj-C's `intValue` and Pascal's `StrToInt()`. Heck, even SQL(ite)'s `cast()` works. I can't think of any language with reasonable standard libraries that *doesn't* do this.<|eor|><|sor|>C#'s Int32.Parse is a parsing function, not a lossless conversion function. Also, what you described is only its default behaviour. It will behave far more strictly if you want it to. I thought Objective-C's intValue returned an int representation of a Number object? Does it work with strings? StrToInt is a parsing function. cast() permits lossy casts. <|eor|><|sor|>Eh, I'll admit to only providing examples in the same vein as previous comments without fully reading the original linked RFC. Mea culpa. I'm not sure of the usefulness of providing lossless round-trip string <=> int conversions, though. Could you suggest a use case? I can see how going int => string => int is useful, but not string => int => string. I don't know much about Objective-C, but [`NSString` does have an `intValue` property](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instp/NSString/intValue).<|eor|><|eoss|><|endoftext|>
5
lolphp
andsens
2ej1j1
<|sols|><|sot|>stdClass is truthy while an empty SimpleXMLElement is falsey<|eot|><|sol|>http://3v4l.org/3hWSY<|eol|><|eols|><|endoftext|>
22
lolphp
andsens
ck02i6u
<|sols|><|sot|>stdClass is truthy while an empty SimpleXMLElement is falsey<|eot|><|sol|>http://3v4l.org/3hWSY<|eol|><|sor|>I don't know if the fact that SimpleXMLElement is a [documented special case](http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting) makes it more or less perplexing. (If it makes you feel any better, that StdClass would have been fasley in PHP 4, which would have been... more consistent? less consistent? less nonsensical? none of the above? I don't know.)<|eor|><|soopr|>I'd definitely say inconsistent. You can't document your way out of inconsistency even though the PHP team likes to think so. Here's another one: $arr = array('first', 'foo' => 'second', 'third'); list($a, $b) = $arr; echo "$a $b"; foreach($arr as $val) {echo "$val";} What's the result? You might have the correct answer, but you'd be lying if you said you didn't have to think about it - and that's exactly the problem. These ambiguities make you mistrust the language and make you doubt your own code.<|eoopr|><|eols|><|endoftext|>
11