Constante

postat acum 4 ani de Stefanescu Mihai in categorie PHP

O constanta este similara unei variabile (in sensul ca este un identificator pentru o valoare), dar spre deosebire de variabile, valorile constantelor nu se pot schimba in timpul executiei scriptului. Constantele sunt case-sensitive, dar prin conventie numele acestora sunt mereu scrise cu litere mari.Pentru a defini o constanta trebuie sa folosesti functia define() si pentru a o apela nu faci decat sa-i scrii numele.Spre deosebire de variabile, numele constantelor nu sunt obligate sa inceapa cu un dolar ($).

Diferente dintre constante si variabile

    • Nu trebuie sa puneti un dolar ($) in fata numelui
    • Pot fi definite decat cu functia define()
    • Pot fi folosite oriunde (chiar si un functii)

O data definita o constanta nu mai poate fi modificata

Numele Constantelor

// Nume Valide
define("ONE",     "Prima constanta");
define("TWO2",    "A doua constanta");
define("THREE_3", "A treia")
// Nume Invalide
define("2TWO",    "a doua");
define("__THREE__", "a treia");

Constante Magice

PHP vine cu o serie de constante predefinite.

Acum discutam despre cele 5 constante magice ce se schimba in functie de locul in care sunt folosite. De exemplu, valoarea constantei __LINE__ depinde de linia pe care este folosita in script.

Nume Descriere
__LINE__ Linia curenta.
__FILE__ Calea completa a fisierului.
__FUNCTION__ Numele functiei.
__CLASS__ Numele clasei.
__METHOD__ Numele metodei.
Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de kobe 9 la data de 15.05.2019
I intended to write you this very little word to be able to say thank you the moment again for those precious concepts you've documented in this case. It is simply wonderfully open-handed with people like you giving extensively what some people would have advertised as an e-book to help with making some cash on their own, certainly given that you might have done it in case you wanted. The solutions in addition served as the great way to understand that many people have the same passion just as mine to realize a lot more with regards to this issue. I think there are a lot more fun situations in the future for individuals that scan your site.
Comentariu postate de download minecraft la data de 15.05.2019
I am actually thankful to the owner of this website who has shared this wonderful paragraph at at this time.
Comentariu postate de how to download minecraft free la data de 17.05.2019
Good way of explaining, and pleasant paragraph to obtain data regarding my presentation focus, which i am going to convey in institution of higher education.
Comentariu postate de minecraft download mojang la data de 18.05.2019
My spouse and I stumbled over here different website and thought I should check things out. I like what I see so now i am following you. Look forward to looking at your web page yet again.