Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,069 members, 7,818,188 topics. Date: Sunday, 05 May 2024 at 09:51 AM

Webmasters Enter Here If You Can Solve These PHP Questions... - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Webmasters Enter Here If You Can Solve These PHP Questions... (9308 Views)

Webmasters: Enter Here And Clarify Me Biko! / Webmasters: Enter Here And Clarify Me Biko! / All Nairaland Webmasters: Enter Here Now!! (2) (3) (4)

(1) (2) (3) (Reply) (Go Down)

Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:10pm On Apr 28, 2015
Hello NL webmasters, I will be posting some Questions in php which I have the answers already and you will figure them out for yourselves. You can also post your own questions here for others to solve.
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:12pm On Apr 28, 2015
Question 1

Q: What is wrong with this query:
"SELECT *
FROM table WHERE id = $_POST
[ 'id' ]" ?
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:16pm On Apr 28, 2015
Question 2

Q: What is the preferred way to write this if
statement, and why?

if( 5 == $someVar ) or
if( $someVar == 5 )
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:17pm On Apr 28, 2015
Question 3

Q: Given this code:

function doSomething( &$arg )
{
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
...what is the value of $a and $b after the
function call and why?
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:31pm On Apr 28, 2015
Question 4

Q: Consider these lines of codes:
//first code
$myVar = "I am Something";

$myVar .= "So Special";

echo "Do you Know $myVar";

And
//second code
$myVar = "I am Something";

$myVar .= "So Special";

echo 'Do you Know $myVar';

Now if you run these two codes in a Browser what will be the output?
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Nobody: 10:51pm On Apr 28, 2015
1.) nothing really,just SQL injection (and probably table should be table name,*sniffs*)


2.).if( $someVar == 5 )...it actually checks if some var is equal to 5 not the other way round..


3.) both a and b are 3 since return is equal to the argument plus that fact that the return variable is what the function outputted..

4.) first one echoes the string the variable is holding while the second does not *updated*

7 Likes 2 Shares

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 10:58pm On Apr 28, 2015
well done jregz but you did'nt get question 4 correctly.
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 11:01pm On Apr 28, 2015
Question 5 (OOP)

Q: What is the difference between p u b l i c, p r o t e c t e d and p r i v a t e in a class definition?
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Nobody: 11:06pm On Apr 28, 2015
FRInteractives:
well done jregz but you did'nt get question 4 correctly.
oh my bad, my eyes kind of failed me....didn't notice the single quote
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by spikesC(m): 11:33pm On Apr 28, 2015
FRInteractives:
well done jregz but you did'nt get question 4 correctly.

Question 1 is also wrong.

FRInteractives:
Question 1

Q: What is wrong with this query:
"SELECT *
FROM table WHERE id = $_POST
[ 'id' ]" ?

You cannot have the single quotes of an array index when the array is in a double quote. It is a syntax error.

Therefore,

"SELECT *
FROM table WHERE id = $_POST
[ id ]"


Pls post reasonable questions, this is really too basic

4 Likes

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 11:37pm On Apr 28, 2015
spikesC:


Question 1 is also wrong.



You cannot have the single quotes of an array index when the array is in a double quote. It is a syntax error.

Therefore,

"SELECT *
FROM table WHERE id = $_POST
[ id ]"


Pls post reasonable questions, this is really too basic

NOTED
good observation
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Craigston: 12:25am On Apr 29, 2015
FRInteractives:
Question 2

Q: What is the preferred way to write this if
statement, and why?

if( 5 == $someVar ) or
if( $someVar == 5 )







Due to right-to-left associativity of the operator being used, if($someVar == 5) is preferred.


1 Like

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 12:33am On Apr 29, 2015
Craigston:
good one bro
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Craigston: 1:02am On Apr 29, 2015
FRInteractives:
Question 5 (OOP)
Q: What is the difference between p u b l i c, p r o t e c t e d and p r i v a t e in a class definition?



I can't put these in exactly correct statements now but I know declaring an object property or a method as public (default) grants outside code access to it and allows sub-classes to inherit it; declaring it as protected denies outside code access to it but allows sub-classes to inherit it and declaring it as private grants only the class methods access to it: outside code cannot access it and sub-classes cannot inherit it


FRInteractives:
Question 4
Q: Consider these lines of codes:
//first code
$myVar = "I am Something";
$myVar .= "So Special";
echo "Do you Know $myVar";
And
//second code
$myVar = "I am Something";
$myVar .= "So Special";
echo 'Do you Know $myVar';
Now if you run these two codes in a Browser what will be the output?


The first code, by Variable Substitution, will output the string 'Do you know I am something so special'; the second code outputs a string literal (using apostrophes instead of quotes) so the output will be 'do you know $myVar'.

FRInteractives:
Question 3
Q: Given this code:
function doSomething( &$arg )
{
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
...what is the value of $a and $b after the
function call and why?


Since the parameter '$arg' is passed by reference, the function accesses its value directly. The expressions in the function will operate directly on its value without making any copy. Therefore, the function 'doSomething' will return 4 and will also change the value of $a to 4.

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by FRInteractives: 3:01pm On Apr 29, 2015
You Nailed it Bro. Keep it up. I'll be posting some more difficult questions soon
Craigston:




Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Craigston: 6:18pm On Apr 29, 2015
FRInteractives:
You Nailed it Bro. Keep it up. I'll be posting some more difficult questions soon
That's great. I'm a beginner so the basics are still fresh in my skull. I hope the harder trivia will spur me on to learn fast. I just finished the basics of objects and arrays, and I'm now learning SQL (MySQL). After that, I'll integrate it with PHP in a small project and learn JS too. Holla.

2 Likes 1 Share

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Nobody: 2:25pm On Apr 30, 2015
Learning mood activated.


Please check my signature too. Thanks.
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by pretydiva(f): 2:25pm On Apr 30, 2015
Walks outta here majestically
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Hollawaley(m): 2:27pm On Apr 30, 2015
Walahi, my head iyaf scatter wit these php codes. Malegirl
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by afrinaija2: 2:28pm On Apr 30, 2015
h
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by hotwax: 2:28pm On Apr 30, 2015
FRInteractives:
Question 1

Q: What is wrong with this query:
"SELECT *
FROM table WHERE id = $_POST
[ 'id' ]" ?


Hackers cake. Prone to attack
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Nobody: 2:28pm On Apr 30, 2015
Hahahaha
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by tunwumi: 2:32pm On Apr 30, 2015
Ok I hear
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by umar4info(m): 2:33pm On Apr 30, 2015
webmasters are also agents of change in this country
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Nobody: 2:35pm On Apr 30, 2015
Funny

1 Like

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by peteruuu(m): 2:35pm On Apr 30, 2015
ff
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Horlaarsco: 2:36pm On Apr 30, 2015
hmmn
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by iykebesbt1(m): 2:36pm On Apr 30, 2015
OP are u reading from the original copy?
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Terahertz(m): 2:38pm On Apr 30, 2015
It will actually return 3 the initial value but will change the variable $a to 4....
Craigston:



Since the parameter '$arg' is passed by reference, the function accesses its value directly. The expressions in the function will operate directly on its value without making any copy. Therefore, the function 'doSomething' will return 4 and will also change the value of $a to 4.

Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Tobilastik(m): 2:40pm On Apr 30, 2015
.
Re: Webmasters Enter Here If You Can Solve These PHP Questions... by Tobilastik(m): 2:43pm On Apr 30, 2015
Craigston:
That's great. I'm a beginner so the basics are still fresh in my skull. I hope the harder trivia will spur me on to learn fast. I just finished the basics of objects and arrays, and I'm now learning SQL (MySQL). After that, I'll integrate it with PHP in a small project and learn JS too. Holla.

where do u learn this?? I need sth like this

2 Likes 1 Share

(1) (2) (3) (Reply)

Has Anyone Noticed That Ogbongeblog Has Been Down Since? / How To Start Gsm Short Code Sms Cool Cash Business With A Token Money / How to Remove Index.php?route=common/home From Opencart

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.