


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Modern Programing Language is about different languages of today era. It explains pros and cons of some new languages and their differences with old ones. Languages like java, c sharp, c plus plus, c, fotran are included in this course. This lecture handout is about: Alternative, Syntax, Database, Function, Arguments, Php, numbers, Functions, string, Argument, Descendants
Typology: Exercises
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Alternative syntax for control statements
PHP offers an alternative syntax for some of its control structures; namely, if , while , for , foreach , and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif; , endwhile; , endfor; , endforeach; , or endswitch; , respectively. An example is shown below:
User defined functions
Just like all programming languages, one can define functions in PHP as shown in the following example:
PHP also allows functions to be defined inside functions. It may be noted that C and its descendents do not support this feature but descendants of Algol generally support it. The following example shows this concept:
php function foo() { function bar() { echo "I don't exist until foo() is called.\n"; } }
/* We can't call bar() yet since it doesn't exist. */
foo();
/* Now we can call bar(), foo()'s processesing has made it
accessible. */
bar(); ?>
PHP also supports recursive functions as shown below:
Function arguments
PHP supports passing arguments by value (the default), passing by reference, and default argument values. If you want an argument to a function to always be passed by reference, you can prepend an ampersand (&) to the argument name in the function definition:
You can't return multiple values from a function, but similar results can be obtained by returning a list as shown below:
To return a reference from a function, you have to use the reference operator & in both the function declaration and when assigning the returned value to a variable:
Classes and Objects
Classes and objects are similar to Java. A variable of the desired type is created with the new operator. It supports Single inheritance only and uses the keyword extends to inherit from a super class. The inherited methods and members can be overridden, unless the parent class has defined a method as final.
Databases
One of the strongest features of PHP is its support for providing web pages access to database. The following example shows database manipulation through ODBC in PHP:
"; echo "Companyname"; echo "Contactname“; while (odbc_fetch_row($rs)){ $compname=odbc_result($rs,"CompanyName"); $conname=odbc_result($rs,"ContactName"); echo "$compname"; echo "$conname"; } odbc_close($conn); echo ""; ?>