What Are Constants & Variable Variables In PHP - Full PHP 8 Tutorial

In this video, you'll learn how to define & use constants in PHP in two ways. You'll also learn what variable variables are & how to use them.
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
⭐ Become a Patreon: / programwithgio
THANK YOU!
LESSON 1.3
Course Outline - github.com/ggelashvili/learnp...
Course Playlist - • Learn PHP The Right Wa...
RESOURCES
Predefined Constants - www.php.net/manual/en/reserve...
Magic Constants - www.php.net/manual/en/languag...
CHAPTERS
00:00 - Intro
00:59 - Using define()
01:28 - Constant Naming Rules
02:00 - Print Constants
02:23 - Check If Constant Has Been Defined
03:05 - Using Const Keyword
03:18 - Differences
04:14 - Dynamic Constant Names
04:49 - When To Use Constants
05:03 - Predefined Constants
05:38 - Magic Constants
06:14 - Variable Variables

Пікірлер: 136

  • 2 жыл бұрын

    This is definitely my go to reference point regarding php. It's so detailed that the documentation doesn't cover everything like Gio does! This should be default search result in KZread when one enter PHP.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thank you so much 🙏

  • @SynMlyn
    @SynMlyn5 ай бұрын

    Gio, your PHP tutorials have been a real game-changer for me. Much appreciated!

  • @ProgramWithGio

    @ProgramWithGio

    5 ай бұрын

    Happy to hear

  • @wasidhossain3848
    @wasidhossain3848 Жыл бұрын

    wow, so many things to learn in just 8 min video. Thanks

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    🙌🙌

  • @cw1847
    @cw18473 жыл бұрын

    Great video. I have seen many tutorials that go over constants, but never in this much detail. I had no clear idea between the differences of const and define. Also, have seen __DIR__ used several times, but never seen anyone explain that they are "magic constants." Thanks for sharing and I'm looking forward to the rest of this course!

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Thank you so much 🙌

  • @user-wg6wo4wy7w
    @user-wg6wo4wy7w5 ай бұрын

    define() and const seems to be small details to talk about, but thank you for this video. I understand their difference better.

  • @ProgramWithGio

    @ProgramWithGio

    4 ай бұрын

    That's great, happy to hear

  • @EhsanShahbazii
    @EhsanShahbaziiАй бұрын

    Thank you for covering the best info in this playlists❤

  • @ProgramWithGio

    @ProgramWithGio

    17 күн бұрын

    You're welcome

  • @brightokoro7073
    @brightokoro70738 ай бұрын

    Thanks for sharing this quality stuff on php step by step,i will love to see the docker alternative

  • @ProgramWithGio

    @ProgramWithGio

    8 ай бұрын

    Awesome, thanks 💙

  • @mmelimahlobo7656
    @mmelimahlobo7656 Жыл бұрын

    If I were to be taught PHP one on one by a teacher as good as you I would be one of the greatest backend developers in this planet,you know PHP like the back of your hand

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you 🙏

  • @med3060
    @med30602 жыл бұрын

    thank you so much for sharing with us your valuable knowledge.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    You're welcome 💙

  • @steelmantv
    @steelmantv Жыл бұрын

    Just got hired on as a developer and a question about constants came up in my technical interview, and this video really helped! Thank you for the great content Gio!

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    That's so awesome, really glad to hear that, great job 💪

  • @misterdanger4727
    @misterdanger47272 ай бұрын

    Super man Even i am an experienced front-end developer but this was soo much helpfull and easy to understand

  • @ProgramWithGio

    @ProgramWithGio

    2 ай бұрын

    Happy to hear 💙

  • @sammclaren6965
    @sammclaren69652 жыл бұрын

    Great job! Keep up the good work!

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thank you 💙

  • @jondo-vh8tx
    @jondo-vh8tx8 ай бұрын

    been going over the basic now., i think its untill lesson 32...my strategy is to go through every of this steps (3 steps) and go back for each step and re do everything again. and interesting enough is you first then relize how much you miss from beeing so focused and how many cool stuff this guy is teaching you FOR FREE. thats all. man i appreciatre your effort so much. you rock

  • @ProgramWithGio

    @ProgramWithGio

    8 ай бұрын

    Happy to hear you like it, thank you 🙌

  • @BuzzRaCHa
    @BuzzRaCHa2 жыл бұрын

    course is really detailed... thankyou

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    You're welcome 💙

  • @user-zh2oz9fe4m
    @user-zh2oz9fe4m11 ай бұрын

    This is a very informative video. Thanks!

  • @ProgramWithGio

    @ProgramWithGio

    11 ай бұрын

    You're welcome

  • @nikolozmacharashvili1212
    @nikolozmacharashvili12122 жыл бұрын

    Good Job on creating these videos Gio :)

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thank you Nikoloz 🙂

  • @alexandershnaidman8188
    @alexandershnaidman81888 ай бұрын

    Great course! Great lessons!

  • @ProgramWithGio

    @ProgramWithGio

    8 ай бұрын

    Thank you 🙏

  • @SoniaChavez-je7hq
    @SoniaChavez-je7hq5 ай бұрын

    Excellent explanation, 😮

  • @ProgramWithGio

    @ProgramWithGio

    4 ай бұрын

    Thank you 💙

  • @faramarztayyari3734
    @faramarztayyari37342 жыл бұрын

    Great video , wish you the best

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thank you. You too

  • @user-lj3sx6cc4x
    @user-lj3sx6cc4x5 ай бұрын

    hello sir i am form india and i have been watching your videos and i like your video very much i have learned php form you and i did not need to do any class

  • @ProgramWithGio

    @ProgramWithGio

    4 ай бұрын

    That's great, keep it up

  • @kristiankoribsky7763
    @kristiankoribsky7763 Жыл бұрын

    I've already watched a couple of php courses but this course is so far the best. For people like me, with some basic programming knowledge, this is the right course. During other courses I got bored and binged read PHP docs along with video as I wanted to know more details about language constructs and their usage. But with you, I don't have to worry about that as your detailed approach is perfect for remembering stuff efficiently and long-term. For example I've never even heard about variable variables! Thank you.

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you so much, I try to be as detailed as I can because that's the way I would want to learn myself if I were starting out with PHP. I'm glad that you like it as well.

  • @Islam.our.religion
    @Islam.our.religion Жыл бұрын

    Thx for the great video and the great series

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you 🙏

  • @jasmine.6296
    @jasmine.62968 ай бұрын

    Thank you so much for this

  • @ProgramWithGio

    @ProgramWithGio

    8 ай бұрын

    You're welcome

  • @faisalasif5986
    @faisalasif59862 жыл бұрын

    Hey, thank you for this wonderful video, I would request if you add some project at the end it will help us eventually that how to use this learning in an actual project.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    We will work on a project at the end

  • @andergraund9327
    @andergraund93273 жыл бұрын

    Great videos!

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Thank you 🙏

  • @MohamedAhmed-ww9bs
    @MohamedAhmed-ww9bs3 жыл бұрын

    great explain go on waiting for next lesson Plz. with PHP 8

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Thank you. Next video will be about data types and type casting. Will be using php8 for the rest of the course

  • @MohamedAhmed-ww9bs

    @MohamedAhmed-ww9bs

    3 жыл бұрын

    ​@@ProgramWithGio Good job Waiting

  • @simxtube
    @simxtube8 ай бұрын

    I have seen many other tutorials on php but I have never seen this kind of detailed videos on php, good work ❤ , and can you please make tutorials also on laravel like this that covers all the important topics in detail..it would be very helpful for me and definitely for many other people..

  • @ProgramWithGio

    @ProgramWithGio

    8 ай бұрын

    Glad you like it, thank you. Yes I'm working on Laravel course. You can subscribe for updates here learnlaraveltherightway.com

  • @sakthivelarumugam4373
    @sakthivelarumugam4373 Жыл бұрын

    Good Job really helpful

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you

  • @janpatio
    @janpatio Жыл бұрын

    Great tutorial.

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you

  • @ollienicholson
    @ollienicholson25 күн бұрын

    awesome!

  • @ProgramWithGio

    @ProgramWithGio

    17 күн бұрын

    Thank you

  • @sparrowp2251
    @sparrowp22512 жыл бұрын

    good vedio i liked it veryy much it helped me a lot gthank you

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Glad it helped, thank you 💙

  • @sparrowp2251

    @sparrowp2251

    2 жыл бұрын

    @@ProgramWithGio are bhot without teachers its sufficient with a bit of hard work ur vedios are enough.

  • @ilya_123__
    @ilya_123__10 ай бұрын

    thank you

  • @ProgramWithGio

    @ProgramWithGio

    10 ай бұрын

    You're welcome

  • @migueldemaria3830
    @migueldemaria38303 жыл бұрын

    variable variable, nice!

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    😎

  • @csilipo
    @csilipo Жыл бұрын

    Hi, I know other people have commented on this series, but it “GREAT!”. Well done. I am trying to learn PHP for projects like; NextCloud and OwnCloud, of which I having trouble finding basic tutorials on these topics online. NextCloud is using Vue3 ( MVC) with their frontend, whilst OwnCloud I think is using PHP. There is a NEED online for someone to teach NextCloud/OwnCloud, if you are interested? Thanks Carlo

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thank you & thanks for the suggestion 🙌💙

  • @PrzyjacielKamil
    @PrzyjacielKamil2 жыл бұрын

    Nice!

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thanks

  • @AnoopD2013
    @AnoopD2013 Жыл бұрын

    Really great series ....... one simple suggestion , it would look, feel and more legible if you could use a theme with better contrast for your editor .

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Thanks for the suggestion, I'm very used to that theme so it won't be easy to switch.

  • @AnoopD2013

    @AnoopD2013

    Жыл бұрын

    @@ProgramWithGio Perfectly OK , thank you for such a fast reply and thanks for this wonderful series !!

  • @jorgetimes2
    @jorgetimes2 Жыл бұрын

    Hi there! Thanks for these videos, they are so condensed and full of information that is so hard to find elsewhere. I have one naive question: in the first lecture you make the distinction between interpreted and compiled languages, where PHP is classified to belong among the interpreted ones. So how is it that you can say that constants defined by means of the `const` keyword are defined at compile time? Could you be more precise what does it mean and how it clicks into the fact that the `const` keyword cannot be used inside the control structures? I don't quite get it. Thank you

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Hey, good question. So PHP is interpreted but it gets compiled down to bytecode. The compilation part is something you don't see or do, happens by the engine behind the scenes so to speak. Other languages like C++ you need to compile it yourself to be able to run, but once compiled, you can run those apps many times, for PHP though compilation happens when you first run the script. This process is usually optimized & cached if using something like opcache so it doesn't keep on recompiling. This is a good article that goes in more detail on how PHP interpreter works: www.droptica.com/blog/how-php-interpreter-works/

  • @jorgetimes2

    @jorgetimes2

    Жыл бұрын

    @@ProgramWithGio Ok, thank you. And how does this imply you can't define your constants inside control structures at compile time?

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    @@jorgetimes2 I updated my answer, I also put a link to the article that goes in more detail about how interpreter works. Hope that helps. From what I've seen, the limitations of const is mostly artificial and not a language limitation itself. Though because it needs to be defined in top level scope & is defined at "compile" time it can't be defined in control structures

  • @jorgetimes2

    @jorgetimes2

    Жыл бұрын

    @@ProgramWithGio Yes, this helps a lot. Thank you

  • @stefanbirsan3320
    @stefanbirsan33203 жыл бұрын

    the best!

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Thanks 🙂

  • @rosarioveneruso9928
    @rosarioveneruso99282 жыл бұрын

    Hi, you say that difference between const and define is that const are defined at compile time and define const at runtime so we can't define constants with const keyword in control structures... ok but why? What does it mean exactly? I tried to answer by myself and I thought that const in a control structure being defined at compile time before the code is run we are not entering in the control structure so when we run the script is not defined yet and we can't access that const (the script is being run but that const is not defined runtime), am I right?

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Yes that is correct

  • @Herobotick2025
    @Herobotick20252 жыл бұрын

    You are awesome

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    No, you're awesome!

  • @SarahPoulin
    @SarahPoulin Жыл бұрын

    I have php 8.2, using Ubuntu 22.04, and I noticed that define('STATUS_PAID', 1); (the second define at about 2:20) did not produce an error, and echo defined('STATUS_VOID'); (at about 3:00) did not show a blank page, but produced an error instead. Also, at 4:48, adding the 4 for define('STATUS_' . $paid, $paid, 4); does not print 4. It continues to print PAID. Does this have to do with you using PHP 7.4 in the video?

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    At 2:20 you should get warning even in 8.2, make sure you have the same constant defined above before defining it again with different value.

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    At 3:00 it should return false and when echoed it prints empty string. What error are you getting, can you share screenshot of your code & error? Maybe a typo.

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    At 4:48 seems like you are setting $paid as the value, you should just set it to 4, do the exact same as in the video, in your example you are doing define('...' . $paid, $paid, 4)

  • @asok1111
    @asok11112 жыл бұрын

    Now I am learning PHP the right way. One question arises here is that php is a scripting language which is not compiled to run the code then how compile time 'const' is used to define constant. It should be only through define function only.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    PHP is interpreted scripting language but there is still compilation going on behind the scenes

  • @asok1111

    @asok1111

    2 жыл бұрын

    @@ProgramWithGio Great info. But like to know how it happens in any video. This will help understanding php working deeply. Thanks for the great video.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    @@asok1111 You're welcome. Thank you for great video suggestion

  • @lasithadulshan7357
    @lasithadulshan73572 жыл бұрын

    wow 🤩

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    😏

  • @codingSparrow143
    @codingSparrow143Ай бұрын

    @ProgramWithGio Hello !!! Nice explanation, sir👍🏻👍🏻. I have a question: Are predefined and magic constants the same? Or magic constants are just a type of predefined constants? Thanks.😃😃

  • @ProgramWithGio

    @ProgramWithGio

    17 күн бұрын

    Pretty much yea

  • @user-zn4bg9bp8a
    @user-zn4bg9bp8a2 жыл бұрын

    From a non-native English learner perspective, a little break (maybe a couple milliseconds longer) between sentences would help to follow the course more effectively.

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    I agree. I improved on that in later videos. I'll try to improve more. Thanks for feedback 👍

  • @foziljonofficial
    @foziljonofficial2 жыл бұрын

    Hello ! How to print "0" in php with 3 line codes ?

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    You can do that with one line, echo '0';.

  • @foziljonofficial

    @foziljonofficial

    2 жыл бұрын

    @@ProgramWithGio thanks but i mean 3 characters...

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    ​@@foziljonofficial Not sure what you mean. Is this a homework question? If it is then paste in the full question because printing 0 in 3 characters doesn't really make sense.

  • @foziljonofficial

    @foziljonofficial

    2 жыл бұрын

    No this isn't homework question...It's Competetive programming task . Someone used 3 character code for completing this task...I understand that he did it when there were no tests for the problem. Thank you bro , much appreciated !

  • @yanuzay0520
    @yanuzay05202 жыл бұрын

    Thanks

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    You're welcome

  • @yanuzay0520

    @yanuzay0520

    2 жыл бұрын

    @@ProgramWithGio Bro which one is better to learn? Symphony or Laravel? I am new i this field

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Laravel is easier to learn, so I would maybe start with Laravel & then advance into Symfony. They are both great frameworks.

  • @yanuzay0520

    @yanuzay0520

    2 жыл бұрын

    @@ProgramWithGio thanks bro

  • @tanzimibthesam5861
    @tanzimibthesam58613 жыл бұрын

    Is it with PHP 8 installed?

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    No, at the time of recording php8 wasn't released. New videos will be using php8

  • @hasannuur8116
    @hasannuur8116 Жыл бұрын

    wow which extension you use

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Do you mean IDE? I use phpstorm

  • @hasannuur8116

    @hasannuur8116

    Жыл бұрын

    @@ProgramWithGio no the plugin

  • @ProgramWithGio

    @ProgramWithGio

    Жыл бұрын

    Plugin for what?

  • @hasannuur8116

    @hasannuur8116

    Жыл бұрын

    @@ProgramWithGio phpstorm i already watch your lesson half,

  • @hasannuur8116

    @hasannuur8116

    Жыл бұрын

    @@ProgramWithGio I don't know how to explain it to you but what else is used inside phpstorm

  • @BenCorvo-iy1nc
    @BenCorvo-iy1nc2 ай бұрын

    echo "Thank you Gio";

  • @ProgramWithGio

    @ProgramWithGio

    2 ай бұрын

    echo 'You're welcome';

  • @rimantasdanilevicius6754
    @rimantasdanilevicius67543 жыл бұрын

    I never saw that someone uses variable variable in practice.

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Yea, you won't see them used much. I personally only use them if I really have to. It's useful for dynamic variable names but makes things harder to read

  • @gedasgedas1720
    @gedasgedas17203 жыл бұрын

    Your --- Magic Constants --- link is wrong it shows --- Predefined Constants ---. Guess I'm the only one who actually clicks the links :D

  • @ProgramWithGio

    @ProgramWithGio

    3 жыл бұрын

    Oops 😄. Fixed it. Thank you

  • @utkarshkaushik6480
    @utkarshkaushik648011 ай бұрын

    I don't actually understand the defining constants with variables part like how does it actually work. 4:16 part of the video is not so much clear to me. if you could actually explain like how does this work then it would be really helpful.

  • @ProgramWithGio

    @ProgramWithGio

    11 ай бұрын

    I explain the difference at 3:18. Define also allows you to use variables in its name so you are able to create dynamic constant names.

  • @DJxMaster2
    @DJxMaster26 ай бұрын

    Now I know why people hate php..

  • @ProgramWithGio

    @ProgramWithGio

    6 ай бұрын

    Good for you

  • @nowsage
    @nowsage2 жыл бұрын

    this tutorial isn't for beginners at all. A beginner will be lost following this

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Sorry to hear that. There are many beginners who found this tutorial very helpful & easy to follow. I think it's beginner friendly but if you are having trouble understanding something feel free to post questions or DM me and I'll be happy to help clear things up 👍

  • @kiwi-Centaur
    @kiwi-Centaur2 жыл бұрын

    super confusing, I've heard 'dont worry about this, we'll do it later" about a dozen times in 3-4 videos, one thing can be done in several ways, and you are going at speed 1.2x

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Sorry to hear that. This is a long series so certain things are covered in later videos when they apply, like class constants since the first section is about procedural PHP, the second section is about OOP so I can't cover OOP together with procedural which is why I say not to worry about it now, we'll get to it soon. Also, things like functions haven't been covered yet so when I reference the word function I simply state to not worry about it because functions are covered in a separate video. It's not like I don't cover it, I just cover it later in the course. About the speed, you are able to adjust the speed on KZread so you can watch it at 0.5x speed 👍. If you have any specific questions or if something didn't make sense feel free to msg me on Twitter, I'll be happy to answer & clear up any confusion.

  • @muhammadsalah3981
    @muhammadsalah39812 жыл бұрын

    Great videos!

  • @ProgramWithGio

    @ProgramWithGio

    2 жыл бұрын

    Thank you