WINTER. Web Development. Template. PHP Variables and Constants. Lecture

Similar documents
PHP by Pearson Education, Inc. All Rights Reserved.

Introduction of PHP Created By: Umar Farooque Khan

What is PHP? [1] Figure 1 [1]

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

Typescript on LLVM Language Reference Manual

Database Systems Fundamentals

Software and Programming 1

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

CA4003 Compiler Construction Assignment Language Definition

CSc Introduction to Computing

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 2 Working with Data Types and Operators

CSC Web Programming. Introduction to JavaScript

PHP. Interactive Web Systems

Web Engineering (Lecture 08) WAMP

JavaScript Functions, Objects and Array

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Software and Programming 1

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Computational Expression

Chapter 2: Overview of C++

PHP Hypertext Preprocessor

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

An Introduction to Processing

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

Lecture 1: Hello, MATLAB!

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

CIW 1D CIW JavaScript Specialist.

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum: Homepage:

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Java Identifiers, Data Types & Variables

C++ Programming: From Problem Analysis to Program Design, Third Edition

Introduction to Python

A First Program - Greeting.cpp

B. V. Patel Institute of BMC & IT 2014

Creating a C++ Program

COSC 122 Computer Fluency. Iteration and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

PHP: Hypertext Preprocessor. A tutorial Introduction

CS242 COMPUTER PROGRAMMING

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Week 3 Lecture 2. Types Constants and Variables

Variables. Data Types.

Fundamentals of Programming CS-110. Lecture 2

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

DEV2QA PDT 1.1. Feature Name : Code Completion Module name : PHPCompletionEngine

PHP: Code Reuse & Functions

Chapter 2: Introduction to C++

PHPoC vs PHP > Overview. Overview

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

C# MOCK TEST C# MOCK TEST I

Introduction to Programming EC-105. Lecture 2

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Python Intro GIS Week 1. Jake K. Carr

Your First Ruby Script

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Lecture 2 Tao Wang 1

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

COMP 202 Java in one week

LECTURE 02 INTRODUCTION TO C++

Computer Programming : C++

Lab # 02. Basic Elements of C++ _ Part1

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

BTE2313. Chapter 2: Introduction to C++ Programming

Programming for the Web with PHP

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

UEE1302 (1102) F10: Introduction to Computers and Programming

Types, Values, Variables & Assignment. EECS 211 Winter 2018

DaMPL. Language Reference Manual. Henrique Grando

COMP284 Scripting Languages Lecture 9: PHP (Part 1) Handouts

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

7 Control Structures, Logical Statements

Client-Side Web Technologies. JavaScript Part I

Ex: If you use a program to record sales, you will want to remember data:

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Course Outline. Introduction to java

2 nd Week Lecture Notes

Identifiers and Variables

Introduction to Programming using C++

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

CS 3360 Design and Implementation of Programming Languages. Exam 1

CGS 3066: Spring 2015 JavaScript Reference

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

DC71 INTERNET APPLICATIONS JUNE 2013

Programming with Java

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Full file at

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

BASIC ELEMENTS OF A COMPUTER PROGRAM

Chapter 2: Basic Elements of C++

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

egrapher Language Reference Manual

Transcription:

WINTER Template Web Development PHP Variables and Constants Lecture-3

Lecture Content What is Variable? Naming Convention & Scope PHP $ and $$ Variables PHP Constants Constant Definition Magic Constants Examples & Coding Practice

What is Variable? Variable is nothing but just a name of the memory location. In simple words, it is a container which is used to store both numeric and non-numeric information. Naming conventions- Variables start with a $, followed by variable name. value VaraibleName Variable name must start with letter or underscore. Variable name can only contain alpha-numeric characters and underscores. Ex- (A-Z, 0-9 and _) Space is not allowed. Variable names are case-sensitive ($age and $AGE are two different variables) A variable name cannot start with a number

Declare Variable A variable is created the moment you assign the value to it. Example- <?php $ number1 = 5; $ number2 = 4; echo Sum=.$ number1 + $ number2;?> Output: Sum= 9

Variable Scope Variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: local global Static

Global Keyword The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function). <?php $number1 = 5; $number2 = 10; function myfunction() { global $ number1, $ number2, $sum; $sum = $ number1 + $ number2; } myfunction (); echo $sum;?> Output 15 Note- PHP also stores all global variables in an array called $GLOBALS[index].

PHP $ and $$ Variables $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. $$var (double dollar) is a reference variable that stores the value of the $variable inside it. Example <?php name 500 var name $var = "name"; $$ var = 500; echo $var."<br/>"; echo $$ var."<br/>"; echo $ name; Output: name 500 500?>

PHP Constants PHP constants are name or identifier that can't be changed during the execution of the script. Differences between constants and variables- There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign. Constants cannot be defined by simple assignment, they may only be defined using the define() function. Constants may be defined and accessed anywhere without regard to variable scoping rules. Once the Constants have been set, may not be redefined or undefined.

PHP Constants PHP constants can be defined by 2 ways: 1. function define() 2. Constant() PHP constants follow the same PHP variable rules. Constants are automatically global and can be used across the entire script.

PHP Constants PHP constant: define() Let's see the syntax of define() function in PHP. 1. define(name, value, case-insensitive) 2. name: specifies the constant name 3. value: specifies the constant value 4. case-insensitive: Default value is false. It means it is case sensitive by default. Example <?php define("firstmessage","hello Learning Veda"); echo FirstMessage;?> Output: Hello Learning Veda

PHP Constants Constant() function Constant function will return the value of the constant. This is useful when you want to retrieve value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a function. Example <?php define("minsize", 50); echo MINSIZE; echo constant("minsize"); // same thing as the previous line?> Output: 50 Note- Only scalar data (boolean, integer, float and string) can be contained in constants.

Magic Constants Name LINE FILE DIR Description Represents current line number where it is used. Represents full path and file name of the file. If it is used inside an include, name of included file is returned. Represents full directory path of the file. Equivalent to dirname( file ). It does not have a trailing slash unless it is a root directory. It also resolves symbolic link. FUNCTION CLASS TRAIT Represents the function name where it is used. If it is used outside of any function, then it will return blank. Represents the function name where it is used. If it is used outside of any function, then it will return blank. Represents the trait name where it is used. If it is used outside of any function, then it will return blank. It includes namespace it was declared in. METHOD NAMESPACE Represents the name of the class method where it is used. The method name is returned as it was declared. Represents the name of the current namespace.

Thanks!! You can find many more Courses on my website