Tuesday, 19 August 2014
Saturday, 15 March 2014
Q: What is
A: Its the scope resolution operator (double colon)
An experienced PHP'er immediately knows what it means. Less experienced (and not Hebrew) developers may want to read this.
But more serious questions now:
Q: What is the cause of this warning: 'Warning: Cannot modify header information - headers already sent', and what is a good practice to prevent it?
A: *Cause:* body data was sent, causing headers to be sent too.
Prevention: Be sure to execute header specific code first before you output any body data. Be sure you haven't accidentally sent out whitespace or any other characters.
Q: What is wrong with this query:
A: 1. It is vulnarable to SQL injection. Never use user input directly in queries. Sanitize it first. Preferebly use prepared statements (PDO) 2. Don't select all columns (*), but specify every single column. This is predominantly ment to prevent queries hogging up memory when for instance a BLOB column is added at some point in the future.
Q: What is wrong with this if statement:
A:
Q: What is the preferred way to write this if statement, and why?
A: The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns (
Q: Given this code:
Q: What is wrong with this code:
Q: What is the difference between an interface and an abstract class?
A: An interface defines a contract between an implementing class is and an object that calls the interface. An abstract class pre-defines certain behaviour for classes that will extend it. To a certain degree this can also be considered a contract, since it garantuees certain methods to exist.
Q: What is wrong with classes that predominantly define getters and setters, that map straight to it's internal members, without actually having methods that execute behaviour?
A: This might be a code smell since the object acts as an ennobled array, without much other use.
Q: Why is PHP's implementation of the use of interfaces sub-optimal?
A: PHP doesn't allow you to define the expected return type of the method's, which essentially renders interfaces pretty useless. :-P
T_PAAMAYIM_NEKUDOTAYIM?A: Its the scope resolution operator (double colon)
An experienced PHP'er immediately knows what it means. Less experienced (and not Hebrew) developers may want to read this.
But more serious questions now:
Q: What is the cause of this warning: 'Warning: Cannot modify header information - headers already sent', and what is a good practice to prevent it?
A: *Cause:* body data was sent, causing headers to be sent too.
Prevention: Be sure to execute header specific code first before you output any body data. Be sure you haven't accidentally sent out whitespace or any other characters.
Q: What is wrong with this query:
"SELECT * FROM table WHERE id = $_POST[ 'id' ]"?A: 1. It is vulnarable to SQL injection. Never use user input directly in queries. Sanitize it first. Preferebly use prepared statements (PDO) 2. Don't select all columns (*), but specify every single column. This is predominantly ment to prevent queries hogging up memory when for instance a BLOB column is added at some point in the future.
Q: What is wrong with this if statement:
if( !strpos( $haystack, $needle ) ...?A:
strpos returns the index position of where it first found the $needle, which could be 0. Since 0 also resolves to false the solution is to use strict comparison: if( false !== strpos( $haystack, $needle )...Q: What is the preferred way to write this if statement, and why?
if( 5 == $someVar ) or if( $someVar == 5 )A: The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns (
$someVar = 5), and will cause an error, the latter won't.Q: Given this code:
function doSomething( &$arg )
{
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
...what is the value of
A: $a and $b after the function call and why?$a is 4 and $b is 3.
The former because $arg is passed by reference, the latter because the
return value of the function is a copy of (not a reference to) the
initial value of the argument.
OOP specific
Q: What is the difference between
A: public, protected and private in a class definition?public makes a class member available to "everyone", protected makes the class member available to only itself and derived classes, private makes the class member only available to the class itself.Q: What is wrong with this code:
class SomeClass
{
protected $_someMember;
public function __construct()
{
$this->_someMember = 1;
}
public static function getSomethingStatic()
{
return $this->_someMember * 5; // here's the catch
}
}
A: Static methods don't have access to $this, because static methods can be executed without instantiating a class.Q: What is the difference between an interface and an abstract class?
A: An interface defines a contract between an implementing class is and an object that calls the interface. An abstract class pre-defines certain behaviour for classes that will extend it. To a certain degree this can also be considered a contract, since it garantuees certain methods to exist.
Q: What is wrong with classes that predominantly define getters and setters, that map straight to it's internal members, without actually having methods that execute behaviour?
A: This might be a code smell since the object acts as an ennobled array, without much other use.
Q: Why is PHP's implementation of the use of interfaces sub-optimal?
A: PHP doesn't allow you to define the expected return type of the method's, which essentially renders interfaces pretty useless. :-P
Saturday, 1 March 2014
PHP Hypertext Pre-processor
The PHP Hypertext Pre-processor (PHP) is a programming language that allows webdevelopers to create dynamic content that interacts with databases.
PHP is basically used for developing web based software applications.
This tutorial helps you to build your base with PHP.
Send your feedback using Contact comments
PHP Introduction
PHP started out as a small open source project that evolved as more and more people found outhow useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
- PHP is a server side scripting language that is embedded in HTML. It is used to manage
dynamic content, databases, session tracking, even build entire e-commerce sites. - It is integrated with a number of popular databases, including MySQL, PostgreSQL,
Oracle, Sybase, Informix, and Microsoft SQL Server. - PHP is pleasingly zippy in its execution, especially when compiled as an Apache module
on the Unix side. The MySQL server, once started, executes even very complex queries
with huge result sets in record-setting time. - PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4
added support for Java and distributed object architectures (COM and CORBA), making
n-tier development a possibility for the first time. - PHP is forgiving: PHP language tries to be as forgiving as possible.
- PHP Syntax is C-Like.
Common uses of PHP:
- PHP performs system functions, i.e. from files on a system it can create, open, read,
write, and close them. - PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can
send data, return data to the user. - You add, delete, modify elements within your database thru PHP.
- Access cookies variables and set cookies.
- Using PHP, you can restrict users to access some pages of your website.
- It can encrypt data.
Five important characteristics make PHP's practical nature possible:
- Simplicity
- Efficiency
- Security
- Flexibility
- Familiarity
"Hello World" Script in PHP:
To get a feel for PHP, first start with simple PHP scripts. Since "Hello, World!" is an essential
example, first we will create a friendly little "Hello, World!" script.
As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML
(or XHTML if you're cutting-edge) you'll have PHP statements like this:
<html>example, first we will create a friendly little "Hello, World!" script.
As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML
(or XHTML if you're cutting-edge) you'll have PHP statements like this:
<head>
<title>Hello World</title>
<body>
<?php echo "Hello, World!";?>
</body>
</html>
Saturday, 22 February 2014
Introducing HTML:
HTML stands for Hypertext Markup Language, and it is the most widely used language to write Web Pages. As its name suggests, HTML is a markup language.- Hypertext refers to the way in which Web pages (HTML documents) are linked together. When you click a link in a Web page, you are using hypertext.
- Markup Language describes how HTML works. With a markup language, you simply "mark up" a text document with tags that tell a Web browser how to structure it to display.
All you need to do to use HTML is to learn what type of markup to use to get the results you want.
Creating HTML Document:
Creating an HTML document is easy. To begin coding HTML you need only two things: a simple-text editor and a web browser. Notepad is the most basic of simple-text editors and you will probably code a fair amount of HTML with it.You can use our HTML Online Editor to learn HTML. Here are the simple steps to create a baisc HTML document:
- Open Notepad or another text editor.
- At the top of the page type <html>.
- On the next line, indent five spaces and now add the opening header tag: <head>.
- On the next line, indent ten spaces and type <title> </title>.
- Go to the next line, indent five spaces from the margin and insert the closing header tag: </head>.
- Five spaces in from the margin on the next line, type<body>.
- Now drop down another line and type the closing tag right below its mate: </body>.
- Finally, go to the next line and type </html>.
- In the File menu, choose Save As.
- In the Save as Type option box, choose All Files.
- Name the file template.htm.
- Click Save.
<html> <head> <title>This is document title</title> </head> <body> <h1>This is a heading</h1> <p>Document description goes here.....</p> </body> </html>
Welcome to my blog.
If you are interested to learn computer science, then you have to remain in touch with mylearningmaterials.blogspot.com/. Hopefully you will learn many more. No matter if you are beginner, intermediate or advance information will be provided for all the three categories. So do participate in posts and coments you will get the correct solutions of your problems.. And also share if you have any inreasted information related to Computer science.
Good luck
If you are interested to learn computer science, then you have to remain in touch with mylearningmaterials.blogspot.com/. Hopefully you will learn many more. No matter if you are beginner, intermediate or advance information will be provided for all the three categories. So do participate in posts and coments you will get the correct solutions of your problems.. And also share if you have any inreasted information related to Computer science.
Good luck