Placeholder Image

字幕表 動画を再生する

  • So let's give you an example of why many coders absolutely hate PHP.

  • As discussed before.

  • When you create and set a variable, you do not have to declare what that variable is.

  • So in many programming languages, you have to declare whether it's an end, whether it's a char, whether it's a string, whether it's a bull where there is a float and many other different data types and PHP used can simply create the variable and then set it to whatever you wanted to set it thio.

  • So if you want to set a variable to be a string, if you want to set a variable to be afloat, if you want to set a variable to be an indicator, you don't have to declare that beforehand.

  • And so the issue with that is that PHP.

  • Then it does not know what a variable is supposed to be, so it simply knows the variable name, and it knows what value you have set the variable, too, but it doesn't know if it's supposed to be a word if it's supposed to be a string.

  • If it's supposed to be an Inter juror, if it's supposed to be afloat and so therefore, you will not get errors if you do something stupid.

  • So that's one of things with a lot of other programming languages.

  • It can be very frustrating to new coders because they will get a lot of errors.

  • But the value of those errors is is that you get the error.

  • That information isn't actually processed.

  • So one of the big problems, especially if you have applications that put information into a database, is the one thing you don't wanna have happen is you don't want bad data going into the database.

  • So what happens if you screw up when you're plugging in your variables?

  • And then you get some kind of weird output?

  • When you try to add those variables together or divide, do some kind of mathematics against the variables.

  • What you want is you want your code to error out, so you know there's a problem there.

  • You don't want to be able to add a string.

  • Tow an editor.

  • You don't want to be ableto you try to to add an integer and a string together and get an output because that would just come out as garbage.

  • One of the issues you have in PHP is that can happen.

  • You can accidentally try to add an integer to a string and then if you're out putting that into your database than that information is going to do your database and then that is going to corrupt the information, the database and basically make it worthless.

  • So that's when the big problems that coders have with PHP is it simply doesn't ever out the way that a lot of other programming languages D'oh.

  • Which means you can get in there and makes it a lot faster for you to be a bit code.

  • But you can create some absolutely garbage code when you d'oh!

  • So let's go over to the computer so I can show you what some of this garbage code can look like.

  • And I can show you the outputs to show why this could be dangerous and PHP So this is a script that I've created that I simply called garbage dot p a.

  • P s.

  • So it looks a lot like the, uh the script that I created for the previous video.

  • Ah, where I created the string, the end and the float variables.

  • The difference here is I'm now going to be adding some of the variables together, and I'm going to show you what the issues are.

  • So of course, we start by calling PHP.

  • Then we come down and we're going to create the variables like we did before.

  • A variable for string of arable for end variable for float.

  • The string is hello world.

  • The end is simply one and the float is 2.2 now, as I talked about before, one of things to remember with variables and PHP is that capitalization matters so lower case float is different.

  • It is literally different than uppercase float.

  • So if you had uppercase f lower case L o A T, that would be different than either of these two.

  • If you had lower case f l o A.

  • And that had upper case T, that would be different.

  • So remember, capitalization matters.

  • So we're going to do here is we're going to create a variable so dollar sign and we're going to create a variable called garbage percent.

  • So we're going to be using this as a garbage variable, and then we're going to make it equal to if we add dollar sign uppercase float plus integer, So we're going to keep the end.

  • So ent looks exactly like the end variable.

  • And so basically what we're going to be doing is we're going to be adding the end the value of N ce to float all upper case.

  • We're going to show you what that value is, then the next thing that we're going to do.

  • And this is one thing that can't be done.

  • A lot of programming language, Chris it would ever out is we're going to create another variable called Garbage too, and so garbage to we're going to make that equal to string plus end.

  • So the value of ent is one.

  • The value of string is hello world, so this shouldn't happen.

  • This should error out and programming languages.

  • And so it's important to understand that if it doesn't error out if you actually get a value, and if you're creating a script that dumps that value again into something like a database that can cause some very big issues, so here again, it's the same, basically the same script we had before to begin with, we're going to print were going to say string and they were going to print the value of string.

  • Then we're going to print ends.

  • We're going to print the value of ent.

  • We're going to print the value of float and then what we're going to do is we're going to print it garbage.

  • So H one garbage, we're going to show it A capitalization error is and what the value should be.

  • So remember, if we're adding flow, if we're adding float to end, we should get 3.2.

  • What do you think we're going to do if we add float all upper case to end?

  • What do you think that value is going to be and then garbage to adding a string?

  • So we're going to have a string Hello world, and we're going to add that to end.

  • Then, of course, we're going to close the PHP, and with that, if we upload it to our server, we're going to see what the output is.

  • And this shows you what the problem is.

  • So string as before is hello.

  • World end as before is one and float as before is 2.2.

  • So this all looks the same.

  • We simply we created the variables we set the variables.

  • And now we're simply printing out the values of variables, and that all looks good.

  • But look at this.

  • So the 1st 2 garbage, this is the capitalization error rights over here.

  • This is where we did uppercase float.

  • Plus, and what you're going to see is it does output a number.

  • It does give you a number.

  • So if this was in code, it's not era ring out.

  • It does give a value of one.

  • So since uppercase float doesn't actually exist, that means the value of other case float is zero.

  • You add one the value of end to zero, and of course you get one.

  • So if this was some kind of database you were adding things together.

  • You screwed up with the capitalization air.

  • Well, now he just got zero plus, whatever the other variable is that got dumped into your database and somebody is going to have a very bad day in about a month when you figure out all your numbers are screwed up dead again with the string, right?

  • So in other programming languages, if you add a string to an end, that should fail.

  • That should fail.

  • But here it works.

  • so garbage to adding a string again.

  • String doesn't have any value as as far as being a number, so it's a sw far as being a mathematical equation.

  • String doesn't have a value, so you essentially end up adding zero to end, which is one.

  • And that, of course, gives you one.

  • So you see that it does set the value of those variables, and then you can actually call that that that that value, you can print that value out.

  • And so if you're doing any kind of script that's going to be collecting information, especially collecting a lot of information, this is where you can run into a lot of problems.

  • Because imagine, imagine if you're trying to average right, you're tryingto average.

  • So you're doing things such as grabbing a whole bunch of test scores or something like that, and then you're going to Africa them together to see what the average of the classes if you start getting a lot of ones and a lot of weird numbers in there, that can really cause a lot of problems.

  • So this is one of the reasons why coders dislike PHP is, since you don't declare what the variables are, you can end up getting a lot of mesas.

  • Faras output is concerned, so that's an example of some garbage code and won the problems that you can run into with how variables are used in PHP.

  • This is one of those things, especially if you're using a basic text editor.

  • You just really have to pay attention to what you're doing.

  • Make sure that the numbers everything looks appropriate.

  • Check.

  • Make sure the output that's coming out actually adds up to what it's supposed to before you actually start putting this into production.

  • Now, if you are using Maur Advanced text editors, if you're using more advanced ID EA ease, they will be able to catch errors like this.

  • But it is important, Understand?

  • It's not that P H P is seeing the error.

  • It's that the I D E or whatever programming environment you're using sees the error so again it is very important.

  • Whenever you're doing PHP just to go back, really do proof reading, really do editing really make sure everything is how it's supposed to be to make sure that the output that's coming out is correct because just because you get an output from Ph.

  • B doesn't mean it's a correct output, and that is a world of difference when you get into the world into coding, and especially once you start dumping data into databases.

  • So that's really all there is to the do garbage code us when you're screwing up variables and that's that's why it matters.

So let's give you an example of why many coders absolutely hate PHP.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

A2 初級

PHP - ガベージコードと不正な変数 (PHP - Garbage Code and Bad Variables)

  • 1 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語