|
| 26 Sep 2015 09:46 AM |
All right how do I check if something exists/doesnt exist in an array? Here is what I have so far but it keeps erroring:
if(!$thing['ClassValue']){ $thing['ClassValue'] = 0; };
Error: Notice: Undefined index: ClassValue
morashsPeasant is sleeping |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Sep 2015 10:00 AM |
Oh thanks :)
morashsPeasant is skrubbing |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 10:02 AM |
Generally use double quotes for indexes in php, it does make a difference. Here's what I do: if (empty($Arr["Index"])) { echo "Index is empty"; } |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 10:10 AM |
That is for the case that $Arr["Index"] = null; right?
morashsPeasant is skrubbing |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 26 Sep 2015 11:10 AM |
| the real problem is that you're using PHP |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 11:23 AM |
PHP IS GOOD Improved performance: PHP 7 is up to twice as fast as PHP 5.6 Consistent 64-bit support Many fatal errors are now Exceptions Removal of old and unsupported SAPIs and extensions The null coalescing operator (??) Combined comparison Operator (<=>) Return Type Declarations Scalar Type Declarations Anonymous Classes |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 11:46 AM |
php operators are weird like this operator: -> and php leads to bad programming practices
https://www.youtube.com/watch?v=-AvRvI9Klu0&t=159s |
|
|
| Report Abuse |
|
|
gskw
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1364 |
|
|
| 26 Sep 2015 11:50 AM |
@BothAngles
http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
Most of the problems listed in the link still apply. |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 11:52 AM |
>mysql_real_escape_string >>real i always knew that php was weird but i cant even asp.net
https://www.youtube.com/watch?v=-AvRvI9Klu0&t=159s |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 26 Sep 2015 11:53 AM |
php isn't "bad"
php is bad if the programmer is bad
If anyone actually fully utilizes the class system and all of the features in a way that they should be used, then PHP is actually a fairly decent language. Most beginner programmers like it because of simplicity, though, so it got a bad reputation because of the people that use it.
so: php is good if the programmer is good
don't just say it's a bad language if you use it wrong |
|
|
| Report Abuse |
|
|
gskw
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1364 |
|
|
| 26 Sep 2015 11:56 AM |
Did you even take a look at the post I linked?
"Do not tell me that “good developers can write good code in any language”, or bad developers blah blah. That doesn’t mean anything. A good carpenter can drive in a nail with either a rock or a hammer, but how many carpenters do you see bashing stuff with rocks? Part of what makes a good developer is the ability to choose the tools that work best." |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 11:56 AM |
i dont use php wrong; i use it for all my websites php is good but its peculiar kind of like visual basic
https://www.youtube.com/watch?v=-AvRvI9Klu0&t=159s |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 11:57 AM |
I do agree with that post gskw, but PHP is very easy and fun to use :) The best part is it doesn't require a 1GB download/messing with makefiles/don't need a compiler/etc |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 26 Sep 2015 11:58 AM |
| @gskw I actually did look at that link. PHP is a good choice at times and bad at others. That doesn't make a bad language, though. |
|
|
| Report Abuse |
|
|
gskw
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1364 |
|
|
| 26 Sep 2015 12:34 PM |
Even the simplest PHP code is broken:
echo "Hello, {$_POST['name']}";
So... - echo is not a function, nor is its friend print. - echo returns void unlike print, which always returns 1. - echo can be used with parenthesis, which enables it to accept multiple arguments. - Which is not true if you're only passing it variables and not string literals. - print can be used with parenthesis as well, but it never accepts multiple arguments. - There is a warning about print being weird as the top comment on its documentation page. - {$_POST['name']} concatenates the "name" value from the $_POST superglobal to the string. If the value doesn't exist, an E_NOTICE will be triggered (those are off by default) and then what? What will go inside the string? I don't exactly know. - Whatever goes there, you would probably waste tons of time debugging your JavaScript code trying to find out what sets a value in your form to that. - And if you were to use single quotes for the string, it would not be possible to insert the value like that. You would have to use the dot operator.
Pretty horrible of a language huh? |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 26 Sep 2015 12:38 PM |
> Most fatal errors are now exceptions
And it took 7 versions to fix that? |
|
|
| Report Abuse |
|
|
|
| 26 Sep 2015 12:48 PM |
@gskw "How are echo and print different in PHP?" Speed. There is a difference between the two, but speed-wise it should be irrelevant which one you use. echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.
Expression. print() behaves like a function in that you can do: $ret = print "Hello World"; And $ret will be 1. That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:
$b ? print "true" : print "false";
print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precedence list though. Only "," AND, OR and XOR are lower.
Parameter(s). The grammar is: echo expression [, expression[, expression] ... ] But echo ( expression, expression ) is not valid. This would be valid: echo ("howdy"),("partner"); the same as: echo "howdy","partner"; (Putting the brackets in that simple example serves no purpose since there is no operator precedence issue with a single term like that.)
So, echo without parentheses can take multiple parameters, which get concatenated:
echo "and a ", 1, 2, 3; // comma-separated without parentheses echo ("and a 123"); // just one parameter with parentheses
print() can only take one parameter:
print ("and a 123"); print "and a 123";
@not It wasn't broken. Fatal errors are kind of like errors that causes C++ to not compile (undefined variables)
|
|
|
| Report Abuse |
|
|
| |
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 26 Sep 2015 01:10 PM |
| I know what fatal errors are. What I'm saying is that it probably shouldn't have taken version 7 for those errors to be handled by exceptions. |
|
|
| Report Abuse |
|
|