By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,496 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,496 IT Pros & Developers. It's quick & easy.

Really hardcore question about PHP needed :)

P: n/a
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)

--
Silly is a state of Mind, Stupid is a way of Life.
Apr 16 '07 #1
Share this Question
Share on Google+
56 Replies


P: n/a
tasteless wrote:
I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.
Setting up an interview for hiring a developer, I guess? ;-)
Where does PHP5 allow parameters by reference: in the function definition,
in the function call, or in both?

What does "Paamayim Nekudotayim" mean?

Hard enough for ya' ?

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Q: Why is Christmas just like a day at the office?
A: You do all of the work and the fat guy in the suit
gets all the credit.

Apr 16 '07 #2

P: n/a
What does "Paamayim Nekudotayim" mean?

lol, nice one.
Apr 16 '07 #3

P: n/a

"tasteless" <ta*******@gazeta.plwrote in message
news:f0**********@inews.gazeta.pl...
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)

--
Silly is a state of Mind, Stupid is a way of Life.
I got one that's been bothering me all day.
What's the implementaion of "array_read()"?
And if you find the answer, please let me know the question.
Vince
Apr 16 '07 #4

P: n/a

"Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:f0**********@hercules.cohp1...
| tasteless wrote:
|
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| Setting up an interview for hiring a developer, I guess? ;-)
|
|
| Where does PHP5 allow parameters by reference: in the function definition,
| in the function call, or in both?

it's both isn't it...and that's been since php 3, hasn't it?
Apr 16 '07 #5

P: n/a

"Vince Morgan" <vi****@REMOVEoptusnet.com.auwrote in message
news:46***********************@news.optusnet.com.a u...
|
| "tasteless" <ta*******@gazeta.plwrote in message
| news:f0**********@inews.gazeta.pl...
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
| >
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
| >
| Thanks and regards - Peter.
| >
| PS. It's about the bet with one of my friend :)
| >
| --
| Silly is a state of Mind, Stupid is a way of Life.
|
| I got one that's been bothering me all day.
| What's the implementaion of "array_read()"?
| And if you find the answer, please let me know the question.
lol. you already won that prize.
Apr 16 '07 #6

P: n/a

"tasteless" <ta*******@gazeta.plwrote in message
news:f0**********@inews.gazeta.pl...
| Hi guys,
|
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
|
| Thanks and regards - Peter.
|
| PS. It's about the bet with one of my friend :)

what's the sqrt of a negative number? now, what does php say it is?

;)
Apr 16 '07 #7

P: n/a

"Steve" <no****@example.comwrote in message
news:TU***********@newsfe04.lga...
>
"Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:f0**********@hercules.cohp1...
| tasteless wrote:
|
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different
part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| Setting up an interview for hiring a developer, I guess? ;-)
|
|
| Where does PHP5 allow parameters by reference: in the function
definition,
| in the function call, or in both?

it's both isn't it...and that's been since php 3, hasn't it?

Warning: Call-time pass-by-reference has been deprecated .
If it's in both ;)
Vince
Apr 16 '07 #8

P: n/a
On Apr 16, 11:54 am, "Vince Morgan" <vin...@REMOVEoptusnet.com.au>
wrote:
"Steve" <no....@example.comwrote in message

news:TU***********@newsfe04.lga...
"Iván Sánchez Ortega" <ivansanchez-...@rroba-escomposlinux.-.punto.-.org>
wrote in messagenews:f0**********@hercules.cohp1...
| tasteless wrote:
|
| I need really hard questions (about 10) about PHP programming (someof
| elements OOP as well, but no MySQL questions - this is different
part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| Setting up an interview for hiring a developer, I guess? ;-)
|
|
| Where does PHP5 allow parameters by reference: in the function
definition,
| in the function call, or in both?
it's both isn't it...and that's been since php 3, hasn't it?

Warning: Call-time pass-by-reference has been deprecated .
If it's in both ;)
Vince
No, not if you use it in both -- only if you use it when calling the
function.

Apr 16 '07 #9

P: n/a
On Apr 16, 10:29 am, tasteless <tastel...@gazeta.plwrote:
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.
Which causes a bigger surge in memory usage, including() a file with a
large array or unserializing the same information after its been
serialized?


Apr 16 '07 #10

P: n/a

tasteless;60646 Wrote:
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different
part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)

--
Silly is a state of Mind, Stupid is a way of Life.
Here is one,

If I _do not_ want to suppress warnings in include(...), (in other word
not use @include(...))
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

FFMG
--

'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
(http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php)
'Free URL redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=13938

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Apr 16 '07 #11

P: n/a

"lawrence k" <lk******@geocities.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
| On Apr 16, 10:29 am, tasteless <tastel...@gazeta.plwrote:
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| Which causes a bigger surge in memory usage, including() a file with a
| large array or unserializing the same information after its been
| serialized?

good one...i'd love to know the correct answers for these. my guess would be
a higher spike when unserializing.
Apr 16 '07 #12

P: n/a

"FFMG" <FF*********@no-mx.httppoint.comwrote in message
news:FF*********@no-mx.httppoint.com...
|
| tasteless;60646 Wrote:
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different
| part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
| >
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
| >
| Thanks and regards - Peter.
| >
| PS. It's about the bet with one of my friend :)
| >
| --
| Silly is a state of Mind, Stupid is a way of Life.
|
| Here is one,
|
| If I _do not_ want to suppress warnings in include(...), (in other word
| not use @include(...))
| Why is file_exists(...) alone not a good option.
| How would you check if a file exists for inclusion.

google is great...file_exists seems to be tied with open_basedir limits in
php.ini.

This error message indicates that the path to your home directory is not
included in allowed paths specified by open_basedir parameter in php.ini
file. open_basedir limits the files that can be opened by PHP to the
specified directory and all included subdirectories. Thus, PHP script is
trying to read a file which is not found in the specified path and the error
occurs.

One way to solve the problem is to include your home directory path in the
path list that PHP is allowed to open, specified by open_basedir. For
example, the following setting indicates that PHP script can read files
located in /home/vhosts, /usr/share/php/pear/ and /tmp folders:

open_basedir =/home/vhosts:/usr/share/php/pear/:/tmp

Another solution is to disable open_basedir restriction and allow open
access to all directories. By default all files are allowed to be opened by
PHP script.
Apr 16 '07 #13

P: n/a
FFMG wrote:
If I _do not_ want to suppress warnings in include(...), (in other word
not use @include(...))
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.
That's too easy.
Just use the filesystem functions.
Apr 16 '07 #14

P: n/a
FFMG kirjoitti:
tasteless;60646 Wrote:
>Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different
part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)

--
Silly is a state of Mind, Stupid is a way of Life.

Here is one,

If I _do not_ want to suppress warnings in include(...), (in other word
not use @include(...))
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

FFMG

Use require instead :D

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Apr 16 '07 #15

P: n/a
On Apr 16, 10:29 am, tasteless <tastel...@gazeta.plwrote:
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)

--
Silly is a state of Mind, Stupid is a way of Life.
How about this one:

You are about to ask a question of some PHP newsgroups. Should you
multi-post or cross-post your message and why? Cite specific examples.

Apr 16 '07 #16

P: n/a
Problem 1:
We want to parse each element of an array contained in an object, but
without leaving the scope of the object, and without use global vars.
Our code contain an error, and you have to find the error, and the solution.
Sample code here :

class object
{
var $lines ;
var $posFound ;

function object()
{
$lines = array( ... ) ;
...
}

function Search($val)
{
/* Line with error : */
array_walk($this->lines, 'searchInLines', $val );

/* solution : */
array_walk($this->lines, array( $this,'searchInLines'), $val );
}

function searchInLines(&line, $id, $valueToSearch)
{
if ( $line[$id] == $valueToSearch )
$this->posFound = $id ;
}
}
--
tasteless wrote:
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?
Apr 16 '07 #17

P: n/a

"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f0**********@nyytiset.pp.htv.fi...
| FFMG kirjoitti:
| tasteless;60646 Wrote:
| >Hi guys,
| >>
| >I need really hard questions (about 10) about PHP programming (some of
| >elements OOP as well, but no MySQL questions - this is different
| >part),
| >this questions needs to be very hard, but the experienced senior PHP
| >developer should answered on it.
| >>
| >I've already searched in google and google groups archive but without
| >any good results. So could anybody help me giving some link or sending
| >some stuff to me ?
| >>
| >Thanks and regards - Peter.
| >>
| >PS. It's about the bet with one of my friend :)
| >>
| >--
| >Silly is a state of Mind, Stupid is a way of Life.
| >
| Here is one,
| >
| If I _do not_ want to suppress warnings in include(...), (in other word
| not use @include(...))
| Why is file_exists(...) alone not a good option.
| How would you check if a file exists for inclusion.
| >
| FFMG
| >
| >
|
| Use require instead :D

you missed the point. @require is the same delima at @include. the question
you're answering is the first one. you have 2 more to answer. :)
Apr 16 '07 #18

P: n/a

"ZeldorBlat" <ze********@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
| On Apr 16, 10:29 am, tasteless <tastel...@gazeta.plwrote:
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
| >
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
| >
| Thanks and regards - Peter.
| >
| PS. It's about the bet with one of my friend :)
| >
| --
| Silly is a state of Mind, Stupid is a way of Life.
|
| How about this one:
|
| You are about to ask a question of some PHP newsgroups. Should you
| multi-post or cross-post your message and why? Cite specific examples.

ROFLMFAO !!!

(the 'why' would be good to know, but we both know the op IS the example. :)
Apr 16 '07 #19

P: n/a

"andre rodier" <an*********@free.frwrote in message
news:46**********************@news.free.fr...
| Problem 1:
| We want to parse each element of an array contained in an object, but
| without leaving the scope of the object, and without use global vars.
| Our code contain an error, and you have to find the error, and the
solution.
| Sample code here :

array_walk, afaicr, is not aware of object instances and therefore would not
be able to find 'searchInLines'...causing your error.

a solution is to simply use array_search...which never leaves php native
code - array_walk does.

another good question to ask is, why do people not standardize their
nomanclature? why pascal 'Search' yet camel everything else including the
name of the class itself?
| class object
| {
| var $lines ;
| var $posFound ;
|
| function object()
| {
| $lines = array( ... ) ;
| ...
| }
|
| function Search($val)
| {
| /* Line with error : */
| array_walk($this->lines, 'searchInLines', $val );
|
| /* solution : */
| array_walk($this->lines, array( $this,'searchInLines'), $val );
| }
|
| function searchInLines(&line, $id, $valueToSearch)
| {
| if ( $line[$id] == $valueToSearch )
| $this->posFound = $id ;
| }
| }
|
|
| --
| tasteless wrote:
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
| >
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
| >
Apr 16 '07 #20

P: n/a

Sanders Kaufman;60683 Wrote:
FFMG wrote:
If I _do not_ want to suppress warnings in include(...), (in other
word
not use @include(...))
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

That's too easy.
Just use the filesystem functions.
Go on, give us an example.
Are you thinking of
if( fopen(...,'r', 1) ){include(...)} ?

That does not always work.

FFMG
--

'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
(http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php)
'Free URL redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=13938

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Apr 16 '07 #21

P: n/a
| class object
| {
| var $lines ;
| var $posFound ;
|
| function object()
| {
| $lines = array( ... ) ;
| ...
| }
|
| function Search($val)
| {
| /* Line with error : */
| array_walk($this->lines, 'searchInLines', $val );
|
| /* solution : */
| array_walk($this->lines, array( $this,'searchInLines'), $val );
| }
|
| function searchInLines(&line, $id, $valueToSearch)
| {
| if ( $line[$id] == $valueToSearch )
| $this->posFound = $id ;
| }
| }

you are aware that &line in searchInLines needs to be &$line...AND that you
are treating it like the array itself when it is actually the VALUE of the
array at key $id...otherwise searchInLines will never set posFound (which
you should do when declaring it anyway).

:)
Apr 16 '07 #22

P: n/a
amygdala wrote:
>What does "Paamayim Nekudotayim" mean?

lol, nice one.
Fact is, you should know the answer if you've encountered a *lot* of parsing
errors.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Apr 16 '07 #23

P: n/a
Steve wrote:
| Which causes a bigger surge in memory usage, including() a file with a
| large array or unserializing the same information after its been
| serialized?

good one...i'd love to know the correct answers for these. my guess would
be a higher spike when unserializing.
.... because you're loading into memory *both* the serialized and
unserialized array.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A: No. Q: Should I include quotations after my reply?
Apr 16 '07 #24

P: n/a

"ZeldorBlat" <ze********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
| Where does PHP5 allow parameters by reference: in the function
definition,
| in the function call, or in both?
it's both isn't it...and that's been since php 3, hasn't it?

Warning: Call-time pass-by-reference has been deprecated .
If it's in both ;)
Vince
No, not if you use it in both -- only if you use it when calling the
function.

Yep, that is certainly correct. And also incorrect.
If you are silly enough to use it in both, similtaneously, you will also
get the above warning. But to do that you would have to be, errr, me.
I read the question like. When will a gearbox break, when it's in first
gear, in reverse, or in both?
Nothing wrong with the question, it's just a mild retardation that shows
itself after bedtime :)
Vince
Apr 17 '07 #25

P: n/a

"Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:f0**********@hercules.cohp1...
| Steve wrote:
|
| | Which causes a bigger surge in memory usage, including() a file with a
| | large array or unserializing the same information after its been
| | serialized?
| >
| good one...i'd love to know the correct answers for these. my guess
would
| be a higher spike when unserializing.
|
| ... because you're loading into memory *both* the serialized and
| unserialized array.

exactly my thought.
Apr 17 '07 #26

P: n/a
Steve wrote:
| class object
| {
| var $lines ;
| var $posFound ;
|
| function object()
| {
| $lines = array( ... ) ;
| ...
| }
|
| function Search($val)
| {
| /* Line with error : */
| array_walk($this->lines, 'searchInLines', $val );
|
| /* solution : */
| array_walk($this->lines, array( $this,'searchInLines'), $val );
| }
|
| function searchInLines(&line, $id, $valueToSearch)
| {
| if ( $line[$id] == $valueToSearch )
| $this->posFound = $id ;
| }
| }

you are aware that &line in searchInLines needs to be &$line...AND that you
are treating it like the array itself when it is actually the VALUE of the
array at key $id...otherwise searchInLines will never set posFound (which
you should do when declaring it anyway).

:)
Sorry, I have tried to simplify the original function by removing some
lines of code. You can find the original code on the application
'bildo', available here : http://bildo.tuxfamily.org/versions/working/
The file is 'albums/engines/index-dat.php'
But the code works, of course.
You can see a demo here : http://hubix.free.fr/bildo/index.php
Apr 17 '07 #27

P: n/a
ZeldorBlat wrote:
You are about to ask a question of some PHP newsgroups. Should you
multi-post or cross-post your message and why? Cite specific examples.
For this same reason why you don't cut useless cites, and signatures :P

Beside it's not cross-posting when you send the post on groups with
similar subject matter, CP is only when you send one message to many
different group and the subject is not connected with the group.

--
Silly is a state of Mind, Stupid is a way of Life.
Apr 17 '07 #28

P: n/a
tasteless wrote:
ZeldorBlat wrote:
>You are about to ask a question of some PHP newsgroups. Should you
multi-post or cross-post your message and why? Cite specific examples.

For this same reason why you don't cut useless cites, and signatures :P

Beside it's not cross-posting when you send the post on groups with
similar subject matter, CP is only when you send one message to many
different group and the subject is not connected with the group.
Wrong. Cross posting is sending a message with multiple groups as the
destination (as opposed to sending identical messages to individual
groups). Whether the subject matter is connected with the group or not
does not enter into the equation.

And sigs of four lines or less are accepted virtually everywhere on usenet.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 17 '07 #29

P: n/a
On Apr 16, 8:16 pm, "Vince Morgan" <vin...@REMOVEoptusnet.com.au>
wrote:
"ZeldorBlat" <zeldorb...@gmail.comwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com...
| Where does PHP5 allow parameters by reference: in the function
definition,
| in the function call, or in both?
it's both isn't it...and that's been since php 3, hasn't it?
Warning: Call-time pass-by-reference has been deprecated .
If it's in both ;)
Vince

No, not if you use it in both -- only if you use it when calling the
function.

Yep, that is certainly correct. And also incorrect.
If you are silly enough to use it in both, similtaneously, you will also
get the above warning. But to do that you would have to be, errr, me.
I read the question like. When will a gearbox break, when it's in first
gear, in reverse, or in both?
Nothing wrong with the question, it's just a mild retardation that shows
itself after bedtime :)
Vince
My point was that you get the error not because you use it in both
places, but because you use it when calling the function. The former
includes the later.

Apr 17 '07 #30

P: n/a

"ZeldorBlat" <ze********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
On Apr 16, 8:16 pm, "Vince Morgan" <vin...@REMOVEoptusnet.com.au>
wrote:
"ZeldorBlat" <zeldorb...@gmail.comwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com...
My point was that you get the error not because you use it in both
places, but because you use it when calling the function. The former
includes the later.
Yep, you're right on the money Zeldor.
My point was that I shouldn't read posts at 1.30am in the morning ,
certainly shouldn't reply to them. And the rest was superfluous.
Vince
Apr 17 '07 #31

P: n/a

"Vince Morgan" <vi****@REMOVEoptusnet.com.auwrote in message
news:46***********************@news.optusnet.com.a u...
>
"ZeldorBlat" <ze********@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
On Apr 16, 8:16 pm, "Vince Morgan" <vin...@REMOVEoptusnet.com.au>
wrote:
"ZeldorBlat" <zeldorb...@gmail.comwrote in message
>
news:11**********************@l77g2000hsb.googlegr oups.com...
My point was that you get the error not because you use it in both
places, but because you use it when calling the function. The former
includes the later.
Yep, you're right on the money Zeldor.
My point was that I shouldn't read posts at 1.30am in the morning ,
certainly shouldn't reply to them. And the rest was superfluous.
Vince

Now I'll go to bed before I do it again ;)
Apr 17 '07 #32

P: n/a
tasteless kirjoitti:
Hi guys,

I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

I've already searched in google and google groups archive but without
any good results. So could anybody help me giving some link or sending
some stuff to me ?

Thanks and regards - Peter.

PS. It's about the bet with one of my friend :)
Well, this might be easy but here we go...

<?php
$i++;
if($i<10) xyz (__FILE__) ;
else echo $i;
?>

Substitute xyz with a standard function or construct so that the output
is 10.

Scroll down for correct answer.














answer: xyz = include, require
Explanation: __FILE__ is included recursively and $i is incremented each
time, until it reaches 10, thus printing 10.
--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Apr 17 '07 #33

P: n/a

"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f0**********@nyytiset.pp.htv.fi...
| tasteless kirjoitti:
| Hi guys,
| >
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
| >
| I've already searched in google and google groups archive but without
| any good results. So could anybody help me giving some link or sending
| some stuff to me ?
| >
| Thanks and regards - Peter.
| >
| PS. It's about the bet with one of my friend :)
| >
|
| Well, this might be easy but here we go...
|
| <?php
| $i++;
| if($i<10) xyz (__FILE__) ;
| else echo $i;
| ?>
|
| Substitute xyz with a standard function or construct so that the output
| is 10.
|
| Scroll down for correct answer.
xyz = unlink() is MUCH more interesting. :)

btw, your if/else formatting is pretty bad, even for an example.
Apr 17 '07 #34

P: n/a
FFMG wrote:
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.
include_path

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 18 '07 #35

P: n/a
tasteless wrote:
I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.
Question 1:

<?php
$i = 5;
$i = 5 + $i++;
echo $i; // What does this print?
?>

Question 2:

Which of the following is wrong? (There may be more than one
which are wrong.)

* in_array($needle, $haystack);
* stristr($needle, $haystack);
* strpos($needle, $haystack);
* preg_match($needle, $haystack);

Question 3:

Describe the output of this code:

<?php
function print_defined_vars ()
{
print_r(get_defined_vars());
}
$a = 1;
$b = 2;
print_defined_vars();
?>

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 18 '07 #36

P: n/a
Rami Elomaa wrote:
<?php
$i++;
if($i<10) xyz (__FILE__) ;
else echo $i;
?>

Substitute xyz with a standard function or construct so that the output
is 10.
My immediate thought would be...

<?php
$i++;
if($i<10) echo preg_replace('/[^\d]/','',file_get_contents(__FILE__));
else echo $i;
?>

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 18 '07 #37

P: n/a
Let me add one other question:
Why would you use the function session_regenerate_id() ?

--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Apr 18 '07 #38

P: n/a
"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:v1************@ophelia.g5n.co.uk...
Rami Elomaa wrote:
><?php
$i++;
if($i<10) xyz (__FILE__) ;
else echo $i;
?>

Substitute xyz with a standard function or construct so that the output
is 10.

My immediate thought would be...

<?php
$i++;
if($i<10) echo preg_replace('/[^\d]/','',file_get_contents(__FILE__));
else echo $i;
?>

Well, that's quite a brilliant solution, but the goal was to use one and
only one function substituting xyz, but you've used three. This was my fault
since I couldn't describe the task correctly. English isn't my native
language and it was late in the evening... Let me try to rephrase the
question:

<?php
$i++;
if($i<=9)
xyz (__FILE__) ;
else
echo $i;
?>

Alter the code above so that the output is 10. Alter the code by replacing
xyz with a single function or construct call. Adding parameters or functions
is not allowed.

Perhaps this sets strict enough conditions for the puzzle. :)

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
Apr 18 '07 #39

P: n/a

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:qg************@ophelia.g5n.co.uk...
tasteless wrote:
I need really hard questions (about 10) about PHP programming (some of
elements OOP as well, but no MySQL questions - this is different part),
this questions needs to be very hard, but the experienced senior PHP
developer should answered on it.

Question 1:

<?php
$i = 5;
$i = 5 + $i++;
echo $i; // What does this print?
?>
I think a C programmer is going to get this one pretty quickly.
10

Apr 18 '07 #40

P: n/a

"Rami Elomaa" <ra*********@gmail.comwrote in message
news:vN*******************@reader1.news.saunalahti .fi...
| "Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
| news:v1************@ophelia.g5n.co.uk...
| Rami Elomaa wrote:
| >
| ><?php
| >$i++;
| >if($i<10) xyz (__FILE__) ;
| >else echo $i;
| >?>
| >>
| >Substitute xyz with a standard function or construct so that the output
| >is 10.
| >
| My immediate thought would be...
| >
| <?php
| $i++;
| if($i<10) echo preg_replace('/[^\d]/','',file_get_contents(__FILE__));
| else echo $i;
| ?>
| >
|
|
| Well, that's quite a brilliant solution, but the goal was to use one and
| only one function substituting xyz, but you've used three. This was my
fault
| since I couldn't describe the task correctly. English isn't my native
| language and it was late in the evening... Let me try to rephrase the
| question:
|
| <?php
| $i++;
| if($i<=9)
| xyz (__FILE__) ;
| else
| echo $i;
| ?>

rami, you've REALLY got to work on your single line if/else formatting.
Apr 18 '07 #41

P: n/a

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:qg************@ophelia.g5n.co.uk...
| tasteless wrote:
|
| I need really hard questions (about 10) about PHP programming (some of
| elements OOP as well, but no MySQL questions - this is different part),
| this questions needs to be very hard, but the experienced senior PHP
| developer should answered on it.
|
| Question 1:
|
| <?php
| $i = 5;
| $i = 5 + $i++;
| echo $i; // What does this print?
| ?>

i see you've taken the $i = $i + $i++ discussion here. you do realize this
effects ALL c-ish languages including javascript, right? :)

since he's betting his 'c' developers, they'll laugh that he thinks it is an
advanced question.

| Question 2:
|
| Which of the following is wrong? (There may be more than one
| which are wrong.)
|
| * in_array($needle, $haystack);
| * stristr($needle, $haystack);
| * strpos($needle, $haystack);
| * preg_match($needle, $haystack);

NONE of the above are wrong. you fail to make constraints on $needle and
$haystack in each function. so as long as the parameter count is correct, i
can imagine each variable has the correct value for making each function run
smoothly. you should start by setting an initial value for $needle and
$haystack before the application of each function. this is not very advanced
either.

| Question 3:
|
| Describe the output of this code:
|
| <?php
| function print_defined_vars ()
| {
| print_r(get_defined_vars());
| }
| $a = 1;
| $b = 2;
| print_defined_vars();
| ?>

uhmmm, is this a head-scratcher? it's all about scope...and this one has
none defined. better than the last two questions though. ;^)

cheers
Apr 18 '07 #42

P: n/a

Toby A Inkster;60885 Wrote:
FFMG wrote:
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

include_path
no.
Doesn't always work.

FFMG
--

'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
(http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php)
'Free URL redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=13938

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Apr 18 '07 #43

P: n/a
Steve kirjoitti:
"Rami Elomaa" <ra*********@gmail.comwrote in message
news:vN*******************@reader1.news.saunalahti .fi...
| "Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
| news:v1************@ophelia.g5n.co.uk...
| Rami Elomaa wrote:
| >
| ><?php
| >$i++;
| >if($i<10) xyz (__FILE__) ;
| >else echo $i;
| >?>
| >>
| >Substitute xyz with a standard function or construct so that the output
| >is 10.
| >
| My immediate thought would be...
| >
| <?php
| $i++;
| if($i<10) echo preg_replace('/[^\d]/','',file_get_contents(__FILE__));
| else echo $i;
| ?>
| >
|
|
| Well, that's quite a brilliant solution, but the goal was to use one and
| only one function substituting xyz, but you've used three. This was my
fault
| since I couldn't describe the task correctly. English isn't my native
| language and it was late in the evening... Let me try to rephrase the
| question:
|
| <?php
| $i++;
| if($i<=9)
| xyz (__FILE__) ;
| else
| echo $i;
| ?>

rami, you've REALLY got to work on your single line if/else formatting.
Please show me the correct formatting. I tried two combinations which
both seem to me ok and understandable, and you've banned both of them.
I'm all out of ideas. It would be REALLY helpful if you could point out
what is wrong with these and secondly what is the correct way. What am I
supposed to do?

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Apr 18 '07 #44

P: n/a
Rami Elomaa wrote:
Steve kirjoitti:
>"Rami Elomaa" <ra*********@gmail.comwrote in message
news:vN*******************@reader1.news.saunalaht i.fi...
| "Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
| news:v1************@ophelia.g5n.co.uk...
| Rami Elomaa wrote:
| >
| ><?php
| >$i++;
| >if($i<10) xyz (__FILE__) ;
| >else echo $i;
| >?>
| >>
| >Substitute xyz with a standard function or construct so that the
output
| >is 10.
| >
| My immediate thought would be...
| >
| <?php
| $i++;
| if($i<10) echo
preg_replace('/[^\d]/','',file_get_contents(__FILE__));
| else echo $i;
| ?>
| >
|
|
| Well, that's quite a brilliant solution, but the goal was to use one
and
| only one function substituting xyz, but you've used three. This was
my fault
| since I couldn't describe the task correctly. English isn't my native
| language and it was late in the evening... Let me try to rephrase the
| question:
|
| <?php
| $i++;
| if($i<=9)
| xyz (__FILE__) ;
| else
| echo $i;
| ?>

rami, you've REALLY got to work on your single line if/else formatting.

Please show me the correct formatting. I tried two combinations which
both seem to me ok and understandable, and you've banned both of them.
I'm all out of ideas. It would be REALLY helpful if you could point out
what is wrong with these and secondly what is the correct way. What am I
supposed to do?
Rami,

There are all kinds of conventions for formatting code. Steve gave you
one, and one of the most popular.

Look at some of the example code in the PHP manual, for instance. And
other code posted here in the newsgroup and around the net.

Not all of it adheres to the same conventions, but you'll soon recognize
many of them.

I like this convention because it makes the code much easier to read and
understand. For instance, I find putting the "then" clause on the same
line as the "if" statement more difficult to read. I guess mainly
because the "if" statement is always executed, but the "then" clause may
or may not be. Placing it on another line helps clarify that.

And indenting under "if" statements, loops, function definitions, etc.
are a very good way to help see program flow.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 18 '07 #45

P: n/a

"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f0**********@nyytiset.pp.htv.fi...
| Steve kirjoitti:
| "Rami Elomaa" <ra*********@gmail.comwrote in message
| news:vN*******************@reader1.news.saunalahti .fi...
| | "Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
| | news:v1************@ophelia.g5n.co.uk...
| | Rami Elomaa wrote:
| | >
| | ><?php
| | >$i++;
| | >if($i<10) xyz (__FILE__) ;
| | >else echo $i;
| | >?>
| | >>
| | >Substitute xyz with a standard function or construct so that the
output
| | >is 10.
| | >
| | My immediate thought would be...
| | >
| | <?php
| | $i++;
| | if($i<10) echo
preg_replace('/[^\d]/','',file_get_contents(__FILE__));
| | else echo $i;
| | ?>
| | >
| |
| |
| | Well, that's quite a brilliant solution, but the goal was to use one
and
| | only one function substituting xyz, but you've used three. This was my
| fault
| | since I couldn't describe the task correctly. English isn't my native
| | language and it was late in the evening... Let me try to rephrase the
| | question:
| |
| | <?php
| | $i++;
| | if($i<=9)
| | xyz (__FILE__) ;
| | else
| | echo $i;
| | ?>
| >
| rami, you've REALLY got to work on your single line if/else formatting.
| >
|
| Please show me the correct formatting. I tried two combinations which
| both seem to me ok and understandable, and you've banned both of them.
| I'm all out of ideas. It would be REALLY helpful if you could point out
| what is wrong with these and secondly what is the correct way. What am I
| supposed to do?

do as you will, i believe though that the standard practice is to include
brackets to clearly show the body block rather than just leaving that to
indentions. this is especially true when multiple if/else if/else statements
are combined. ex.

if ($i <= 9)
{
xyz (__FILE__);
} else {
echo $i;
}

that makes the 'if' stand out clearly as well as the operations being
performed for each condition checked. also note the space between 'if' and
'(' . 'if' is not a function. notice the space on either side of '<=' . the
space makes it easier to see/read the variable, the condition, and the value
being evaluated.

i'm not ragging on you, but these points make it easier to manage code.

cheers.
Apr 18 '07 #46

P: n/a
FFMG wrote:
Toby A Inkster;60885 Wrote:
>FFMG wrote:
Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

include_path

no.
Doesn't always work.
Well, if you may want to check it's readable, as permissions may prevent
PHP from reading the file. You could also run "php -l" on the sile using
system() to check for syntax errors in the file first.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 18 '07 #47

P: n/a
Steve wrote:
Toby A Inkster:

| Question 1:
|
| <?php
| $i = 5;
| $i = 5 + $i++;
| echo $i; // What does this print?
| ?>

i see you've taken the $i = $i + $i++ discussion here. you do realize this
effects ALL c-ish languages including javascript, right? :)
Indeed I do.
since he's betting his 'c' developers, they'll laugh that he thinks it
is an advanced question.
The OP didn't mention of whom he was intending to ask the questions in the
original post. And even so, it's the kind of question that it's very easy
to make a mistake answering. The so called "smiple" question. Think a tonne
of lead vs a tonne of feathers.
| Question 2:
|
| Which of the following is wrong? (There may be more than one
| which are wrong.)
|
| * in_array($needle, $haystack);
| * stristr($needle, $haystack);
| * strpos($needle, $haystack);
| * preg_match($needle, $haystack);

NONE of the above are wrong. you fail to make constraints on $needle and
$haystack in each function.
One assumes of course, that you are intending to search $haystack for
$needle. That is the normal usage of those metasyntactic variables, and it
is used consistently in the PHP documentation. Anyone not understanding
that should be failed automatically anyway.

http://en.wikipedia.org/wiki/Metasyn...e_and_haystack
| Question 3:
|
| Describe the output of this code:
|
| <?php
| function print_defined_vars ()
| {
| print_r(get_defined_vars());
| }
| $a = 1;
| $b = 2;
| print_defined_vars();
| ?>

uhmmm, is this a head-scratcher?
Nope. But it's more fun to pick an innocuous looking question with a
gotcha that they might not spot, than to just post an enormous 1000 line
chunk of impenetrable code and say "find the syntax error in that".

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 18 '07 #48

P: n/a

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:mo************@ophelia.g5n.co.uk...
| Steve wrote:
| Toby A Inkster:
| >
| | Question 1:
| |
| | <?php
| | $i = 5;
| | $i = 5 + $i++;
| | echo $i; // What does this print?
| | ?>
| >
| i see you've taken the $i = $i + $i++ discussion here. you do realize
this
| effects ALL c-ish languages including javascript, right? :)
|
| Indeed I do.
|
| since he's betting his 'c' developers, they'll laugh that he thinks it
| is an advanced question.
|
| The OP didn't mention of whom he was intending to ask the questions in the
| original post. And even so, it's the kind of question that it's very easy
| to make a mistake answering. The so called "smiple" question. Think a
tonne
| of lead vs a tonne of feathers.

i know...he multi-posted to just about every other php ng out there, and in
one of them he mentioned it was a bet between php and c developers. i just
couldn't remember if it was in this group that he said it.

good point about simple being most complex. although i'm not sure i get the
ton of lead v ton of feathers...still a ton, right?

| | Question 2:
| |
| | Which of the following is wrong? (There may be more than one
| | which are wrong.)
| |
| | * in_array($needle, $haystack);
| | * stristr($needle, $haystack);
| | * strpos($needle, $haystack);
| | * preg_match($needle, $haystack);
| >
| NONE of the above are wrong. you fail to make constraints on $needle and
| $haystack in each function.
|
| One assumes of course, that you are intending to search $haystack for
| $needle. That is the normal usage of those metasyntactic variables, and it
| is used consistently in the PHP documentation. Anyone not understanding
| that should be failed automatically anyway.

brrrrr! wrong answer. on tests, assumption is the err of the test maker, not
the test taker! why? because most test's questions are trying to see the
extent of one's ability to reason and think clearly through the states
scenarios and give the best solution. it is the test taker's assumption that
keeps him from scoring high marks on iq tests...see mensa.org if you'd care
to argue this further. as a member, i can tell you there is a whole world of
test creation strategy out there and *most* involve duping the taker into
making an assumption. it simply seperates the grain from the chaff.

| http://en.wikipedia.org/wiki/Metasyn...e_and_haystack

OMFG! your reference is wiki? ROFLMFAO! so, since $needle and $haystack are
'reserved' words to you, do you have any other magic numbers...errr...i
mean, variables that a test taker should know? that's especially true if
they're from another locale than you - they just may have never encountered
such a thing as 'need' or 'haystack'.

LOL

| | Question 3:
| |
| | Describe the output of this code:
| |
| | <?php
| | function print_defined_vars ()
| | {
| | print_r(get_defined_vars());
| | }
| | $a = 1;
| | $b = 2;
| | print_defined_vars();
| | ?>
| >
| uhmmm, is this a head-scratcher?
|
| Nope. But it's more fun to pick an innocuous looking question with a
| gotcha that they might not spot, than to just post an enormous 1000 line
| chunk of impenetrable code and say "find the syntax error in that".

i wouldn't say the latter is 'advanced' questioning either; just highly
inefficient. i like the ones like:

$value = 0;
for ($incrementor = 0; $incrementor < 10; $incrementor++)
{
$value += $value % $incrementor;
}

what is the value of $incrementor?

most actually try to calculate in their head or on the test what the value
of $value is. duh. btw, that form of questioning is bating
assumption...which we've already covered. :)
Apr 18 '07 #49

P: n/a

Toby A Inkster;60934 Wrote:
FFMG wrote:
Toby A Inkster;60885 Wrote:
FFMG wrote:

Why is file_exists(...) alone not a good option.
How would you check if a file exists for inclusion.

include_path
no.
Doesn't always work.

Well, if you may want to check it's readable, as permissions may
prevent
PHP from reading the file. You could also run "php -l" on the sile
using
system() to check for syntax errors in the file first.

What?
Access has nothing to do with it.

That is not a solution to the problem I was giving.
I want to use include(...), not @include(...), how can I check if the
file can be included.

FFMG
--

'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
(http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php)
'Free URL redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=13938

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Apr 18 '07 #50

56 Replies

This discussion thread is closed

Replies have been disabled for this discussion.