PHP Variable Scopes - Static Variables - Full PHP 8 Tutorial

preview_player
Показать описание
In this PHP tutorial, you will learn what variable scope is, global & local scopes, & more. You will also learn how you can use static variables to optimize your code & cache the value of expensive function calls.

SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
THANK YOU!

LESSON 1.23

CHAPTERS
00:00 - Variable scope
00:25 - Global scope
01:00 - Local scope
01:41 - Using global keyword to access variables in the global scope
02:12 - How are global variables stored & GLOBALS superglobal
03:13 - Static variables
Рекомендации по теме
Комментарии
Автор

I decided to finally go thought your whole PHP course. I am a working PHP developer but there are some holes in my understanding since I am self taught. This course has been great at helping me fill in some holes and learn about edge cases I was not aware of. Each video is very quick(especially at x2 speed) but they are packed full of information that you also somehow make easy to understand, even at x2 speed! Lets see if I keep up this pace once I hit the second and third chapters ;)

glyakk
Автор

I always leave a like after watching the entire video so the youtube algorithm works correctly and hopefully gives you more views :)

aleksandrkanygin
Автор

I am an experienced developer but for years I was only working with the frameworks so wanted to brush up on my basics again. Your series is just what I wanted, these lessons are on point. Keep up the great work!!👏👏

rohitpatil
Автор

Love you bro, I am literally understanding everything. Best PHP course ive ever taken

vilhelm
Автор

I found in your videos the explanation to problems that made me lose hours.. Thanks for the hard work you did.

__byteWise
Автор

Really didn't understand the static variable use.
If you could explain it again in a more simple way, I would appreciate it.
And thanks by the way for these great tutorials, they helped a lot.

ahmedmohammedjayantimochi
Автор

Thank you very much I am taking your course continuously it is a wonderful course is increasing my knowledge and I am learning a lot.

raohammadraza
Автор

Yet again I learned something very basic but important. O was seeing static all over the place but I did not know what it means. Now I do 😜 next thing aı want to learn is @

keremardicli
Автор

This lesson is pretty useful. Thanks a lot again!

Vitalii-mr
Автор

It would be awesome if you can explain about why the running sleep(2) will be called 3 times and you compared the result with PHP CLI. Using PHP CLI (not in browser), you will have the exact sleep delay (2 seconds) with no issue. For browser the sleep would be called 6 seconds.

maxibi
Автор

Six years with PHP, and I didn't even know about static variables in function, shame on me :D

ondottr
Автор

Thank you Gio for these great tutorials. I learned a lot from you.
could you please explain more about "caching" that is mentioned in this tutorial?
does it mean static variables in php sit in memory or heap or something like that? or am I wrong?!
thanks

vivamedia
Автор

in real life scenario i dont know how exactly you would use this method 5:22. Ususally when you call a function, the value will be dependent on smthing thus different everytime, so it wouldnt really workout...

alfsaboltins
Автор

why did this work only for the first function call?
static $value= null;

was it excuted only in the first time we called the function?

if it was executed in the 2nd and 3rd time it would have overwritten the value of $x to null always
right?
so, is this what you mean by saying that static variables are cached?

Edit:
asked chat gpt, now I know that a static variable can be initialized only once, next re-initializations won't affect it
now it makes sense

omaryahia
Автор

Are we gonna learn about static more in OOP, or is it all we need to know about static Gio?

Armando-pxhi
Автор

Hi. How can I switch the displaying of operators in PHPStorm (!=, ==, ===, => etc.) like yours. They are looking pretty good and non-standard on your IDE.

artyomaghababyan
Автор

I have doubt at 5:11 in tutorial, when we called getValue() second time, then didn't we assigned the static variable $value to the null (static $value = null), So didn't it execute the someVeryExpensiveFunction() second time?

patel
Автор

For now only 2912 people learns PHP right way on yt

jewgienijbrzozowski
Автор

I use the include method to link the script1 file to the index file. But when I echo out the variable $x in script1.php it says undefined. 0:48

DMZee
Автор

Hey gio,
i still don't understand what is the use case of static?
i am trying to udnerstand the logic rather than programming so i want to know why do we need static variables?

subjectfrank