Re: [PHP] Re: Function size

2012-06-03 Thread Tony Marston

"Tim Streater"  wrote in message news:d0.7c.45755.25a3b...@pb1.pair.com...


On 03 Jun 2012 at 10:02, Tony Marston  wrote:


"tamouse mailing lists"  wrote in message
news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...



There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.


I *never* have huge numbers of lines between a block beginning and end. 
Even

if I did my IDE can quickly find the other end of the block for me.


E.g. TextWrangler does this easily enough: just double-click immediately 
after an opening brace, and everything is highlighted to the closing brace.



- all those functions should be arranged in alphabetical order within
their containing file - having them in a random sequence makes it
difficult to find the one you want.


Also correct; this is a key point in making sure your scripts are
maintainable.


Ah-ha! So someone agrees with me on that point after all.


+1


- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my
mouse
than keep jumping from one position in the file to another.


May I suggest an editor/IDE that lets you navigate to functions 
directly,

then?


I am *NOT* going to change my IDE just to suit *YOUR* preferences.


TW provided a popup list of your functions. It still helps to have them in 
alpha order though, for ease of navigation in the popup list.


[snip arguments]

I write functions to do specific things. E.g. I have a function (actually 
in JavaScript) called switchTab() which switches from one user view to 
another. It's just over 200 lines long and is mostly a giant case 
statement - and it's already loaded with function calls. I suppose I could 
break it up into five separate functions, more or less one for each case 
value, but then I'd have lots of unimportant local variables to pass around 
as argument values, and, what's worse, lots of unimportant functions 
cluttering the place up.


Exactly! That's one good reason *NOT* to break up a large function into 
artificially small pieces. You generate a lot of useless code just to handle 
the small pieces, and wading through lots of useless code makes it less 
readable. In my opinion it takes less effort to use the scroll wheel on my 
mouse than it does to jump/return from different parts of the file. There 
are times when it makes sense to split a large function into smaller pieces, 
but I'm afraid that doing so for no other reason than to satisfy someone's 
personal line limit is just not good enough.


--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-06-03 Thread Tim Streater
On 03 Jun 2012 at 10:02, Tony Marston  wrote: 

> "tamouse mailing lists"  wrote in message
> news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...

>> There is a point: if you are unfamiliar with code, wading through
>> screens and screens of a function to find things like block
>> beginning/ends makes for difficult time finding places where changes
>> need to be made.
>
> I *never* have huge numbers of lines between a block beginning and end. Even
> if I did my IDE can quickly find the other end of the block for me.

E.g. TextWrangler does this easily enough: just double-click immediately after 
an opening brace, and everything is highlighted to the closing brace.

>>> - all those functions should be arranged in alphabetical order within
>>> their containing file - having them in a random sequence makes it
>>> difficult to find the one you want.
>>
>> Also correct; this is a key point in making sure your scripts are
>> maintainable.
>
> Ah-ha! So someone agrees with me on that point after all.

+1

>>> - when browsing through the code you have to keep jumping to another
>>> function, and then returning to where you came from.
>>>
>>> I don't know about you, but I would rather use the scroll wheel on my
>>> mouse
>>> than keep jumping from one position in the file to another.
>>
>> May I suggest an editor/IDE that lets you navigate to functions directly,
>> then?
>
> I am *NOT* going to change my IDE just to suit *YOUR* preferences.

TW provided a popup list of your functions. It still helps to have them in 
alpha order though, for ease of navigation in the popup list.

[snip arguments]

I write functions to do specific things. E.g. I have a function (actually in 
JavaScript) called switchTab() which switches from one user view to another. 
It's just over 200 lines long and is mostly a giant case statement - and it's 
already loaded with function calls. I suppose I could break it up into five 
separate functions, more or less one for each case value, but then I'd have 
lots of unimportant local variables to pass around as argument values, and, 
what's worse, lots of unimportant functions cluttering the place up.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Re: Function size

2012-06-03 Thread Tony Marston
"tamouse mailing lists"  wrote in message 
news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...


On Tue, May 29, 2012 at 2:52 AM, Tony Marston
 wrote:

On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:

 A rule of thumb is no more than 50 lines per
function, most much less. Back in the day when we didn't have nifty
gui screens and an 24 line terminals (yay green on black!), if a
function exceeded one printed page, it was deemed too long and marked
for refactoring.


I think the idea of setting an arbitrary limit on the number of lines 
that a

function should contain is quite ludicrous and something which I will
completely ignore. If a function requires a hundred or more lines then so 
be
it. The only reason to take a block of code and put it into its own 
function
is when that code is likely to be called more than once so that it 
conforms
to the DRY principle. If it is only ever used in one place then there is 
no

point.



You obviously haven't spent much time maintaining other people's code.


I have been maintaining other people's code, which have been written to many 
different standards of varying quality, for many years.



There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.


I *never* have huge numbers of lines between a block beginning and end. Even 
if I did my IDE can quickly find the other end of the block for me.



If you will never have your code maintained by anyone else, or
collaborate with anyone else, feel free to do what you want.


My code has been available in an open source framework for over 6 years, and 
I have never received any complaints on the readability of my code, only 
compliments.




The problems I have with creating lots of small used-only-once functions 
is

as follows:
- you have to create a meaningful name for each function.


Yes, you do, which is also considered a hallmark of good design.

- all those functions should be arranged in alphabetical order within 
their

containing file - having them in a random sequence makes it difficult to
find the one you want.


Also correct; this is a key point in making sure your scripts are 
maintainable.


Ah-ha! So someone agrees with me on that point after all.


- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my 
mouse

than keep jumping from one position in the file to another.


May I suggest an editor/IDE that lets you navigate to functions directly, 
then?


I am *NOT* going to change my IDE just to suit *YOUR* preferences.

Another problem I have encountered in the past with such an idea is that 
it

encourages a stupid programmer to decrease the number of lines of code by
compressing as many statements as possible into a single line, which then
makes the code less easy to read and understand. This is much worse than
having more than 20 lines in a function.


There are counterbalancing things as well. If the only aspect of one's
coding standards are "make it fit on one screen" then yes, you might
see someone idiotic enough to do that. However, a good set of coding
standards includes things which will prevent this, such as not
stacking code like that.

Whether a file contains 10 functions of 100 lines each, or 100 functions 
of
10 lines each, you still end up with 1000 lines of code. If you do not 
have

the mental capacity to deal with a 100-line function then you are in the
wrong job.


The rules of thumb for coding standards are for maintainability,
primarily, so throwing up strawmen to try to weasel out of an idea is
pretty specious.


I will only follow standards which have a genuine purpose and a genuine 
benefit. I will *NOT* follow any which I consider to be arbitrary, 
artificial and pointless. There is *NO* limit to the number of lines in a 
function/method, and there is *NO* limit on the number of methods within a 
class. The only thing that matters is that the code is readable and 
maintainable. If some functions overflow the current screen then LEARN TO 
USE THE MOUSE WHEEL! That is what is was invented for in the first place. I 
will *NOT* make my code more difficult to read by creating a huge number of 
artificially small functions.



If you do not care about how much time it takes to fix defects in
other people's code, then I hope you remain a solitary programmer and
don't expect anyone else to use your code, otherwise, you are in the
wrong job.


I *DO* care, which is why I write code which is readable and maintainable.

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-31 Thread tamouse mailing lists
On Tue, May 29, 2012 at 2:52 AM, Tony Marston
 wrote:
> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
>>  A rule of thumb is no more than 50 lines per
>> function, most much less. Back in the day when we didn't have nifty
>> gui screens and an 24 line terminals (yay green on black!), if a
>> function exceeded one printed page, it was deemed too long and marked
>> for refactoring.
>
> I think the idea of setting an arbitrary limit on the number of lines that a
> function should contain is quite ludicrous and something which I will
> completely ignore. If a function requires a hundred or more lines then so be
> it. The only reason to take a block of code and put it into its own function
> is when that code is likely to be called more than once so that it conforms
> to the DRY principle. If it is only ever used in one place then there is no
> point.


You obviously haven't spent much time maintaining other people's code.
There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.

If you will never have your code maintained by anyone else, or
collaborate with anyone else, feel free to do what you want.



>
> The problems I have with creating lots of small used-only-once functions is
> as follows:
> - you have to create a meaningful name for each function.

Yes, you do, which is also considered a hallmark of good design.

> - all those functions should be arranged in alphabetical order within their
> containing file - having them in a random sequence makes it difficult to
> find the one you want.

Also correct; this is a key point in making sure your scripts are maintainable.

> - when browsing through the code you have to keep jumping to another
> function, and then returning to where you came from.
>
> I don't know about you, but I would rather use the scroll wheel on my mouse
> than keep jumping from one position in the file to another.

May I suggest an editor/IDE that lets you navigate to functions directly, then?

> Another problem I have encountered in the past with such an idea is that it
> encourages a stupid programmer to decrease the number of lines of code by
> compressing as many statements as possible into a single line, which then
> makes the code less easy to read and understand. This is much worse than
> having more than 20 lines in a function.

There are counterbalancing things as well. If the only aspect of one's
coding standards are "make it fit on one screen" then yes, you might
see someone idiotic enough to do that. However, a good set of coding
standards includes things which will prevent this, such as not
stacking code like that.

> Whether a file contains 10 functions of 100 lines each, or 100 functions of
> 10 lines each, you still end up with 1000 lines of code. If you do not have
> the mental capacity to deal with a 100-line function then you are in the
> wrong job.

The rules of thumb for coding standards are for maintainability,
primarily, so throwing up strawmen to try to weasel out of an idea is
pretty specious.

If you do not care about how much time it takes to fix defects in
other people's code, then I hope you remain a solitary programmer and
don't expect anyone else to use your code, otherwise, you are in the
wrong job.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Function size

2012-05-30 Thread admin


-Original Message-
From: Paul M Foster [mailto:pa...@quillandmouse.com] 
Sent: Wednesday, May 30, 2012 10:54 AM
To: php-general@lists.php.net
Subject: Re: [PHP] Re: Function size

On Wed, May 30, 2012 at 04:31:12PM +0200, Sebastian Krebs wrote:


[snip]

> 
> If the functions were named properly you don't have to follow every 
> execution path to the deepest deep. Or do you reading PHPs C-source, 
> just because a wild "substr()" appeared? When you see a method
"loadFromFile()"
> and the IDE tells you, that it expects a $filename as parameter, why 
> should you jump there just to make sure, that the method loads 
> something from a file by the filename given as first parameter?

Here's why, and I've seen this happen a *lot*. The function may be properly
named, but have side effects. Or the guy who named the function
*thought* it was properly named, but was wrong. For example, he may have
named the function "loadFromFile()", and the function does in fact do that.
What the name doesn't tell you is that it then erases the file from which it
pulled. Oops! No, you're correct, the function is *not* properly named in
that case. But the guy who wrote it thought it was.
And before I look at the internals of the function, I don't know whether
it's properly named or not. Worse, the side effects may not show up until
later, and then with disasterous results. Imagine assuming everything's
okay, patching your code into the system, and finding out that it's been
hacking up the customer's filesystem for the last three weeks. All because
you didn't check to see what that other function was
*actually* doing.

Rule: NEVER assume you know what a function is doing by looking at its name.
ALWAYS satisfy yourself that you know what a function is doing by
*looking* at what it's doing.

Paul

--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

---

That is WHY you put Function Definitions / Relations 


Rick.







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-30 Thread Paul M Foster
On Wed, May 30, 2012 at 04:31:12PM +0200, Sebastian Krebs wrote:


[snip]

> 
> If the functions were named properly you don't have to follow every
> execution path to the deepest deep. Or do you reading PHPs C-source, just
> because a wild "substr()" appeared? When you see a method "loadFromFile()"
> and the IDE tells you, that it expects a $filename as parameter, why should
> you jump there just to make sure, that the method loads something from a
> file by the filename given as first parameter?

Here's why, and I've seen this happen a *lot*. The function may be
properly named, but have side effects. Or the guy who named the function
*thought* it was properly named, but was wrong. For example, he may have
named the function "loadFromFile()", and the function does in fact do
that. What the name doesn't tell you is that it then erases the file
from which it pulled. Oops! No, you're correct, the function is *not*
properly named in that case. But the guy who wrote it thought it was.
And before I look at the internals of the function, I don't know whether
it's properly named or not. Worse, the side effects may not show up
until later, and then with disasterous results. Imagine assuming
everything's okay, patching your code into the system, and finding out
that it's been hacking up the customer's filesystem for the last three
weeks. All because you didn't check to see what that other function was
*actually* doing.

Rule: NEVER assume you know what a function is doing by looking at its
name. ALWAYS satisfy yourself that you know what a function is doing by
*looking* at what it's doing.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Function size

2012-05-30 Thread Steven Staples
> Paul,
> 
> Are you stating here that compression is a bad thing?
> 
> That means you consider this nice:
> 
> if ( action == A )
> {
> doA();
> }
> else if (action == B )
> {
> doB();
> }
> else
> {
> doC();
> }
> 
> Or perhaps flooded with comments that merely say the same as the code does?
> 
> I'd go for
> if(action == A)
> doA();
> else if(action == B)
> doB();
> else
> doC();
> 
> or , if it's really that clean, i'd probably go for if(action == A)  doA();
> else if(action == B)  doB(); else doC();
> 
> - Matijn

How about this:

($action == 1? doA():($action == 2? doB(): doC()));



Steve.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-30 Thread Paul M Foster
On Tue, May 29, 2012 at 11:40:25PM +0200, Matijn Woudt wrote:

[snip]

> On Tue, May 29, 2012 at 11:06 PM, Paul M Foster  
> wrote:

[snip]

> >
> > I think a lot of coders try to be kewler than the next 18 guys who are
> > gonna have to look at the code, so they use a lot of "compression"
> > techniques to reduce LOC. Plus, they're lazy. I'd rather see everything
> > with lots of spaces and plenty of comments and blank lines. Especially
> > since I'm sometimes that 18th guy to look at the code.
> >
> > Paul
> 
> Paul,
> 
> Are you stating here that compression is a bad thing?
> 
> That means you consider this nice:
> 
> if ( action == A )
> {
> doA();
> }
> else if (action == B )
> {
> doB();
> }
> else
> {
> doC();
> }
> 
> Or perhaps flooded with comments that merely say the same as the code does?
> 
> I'd go for
> if(action == A)
> doA();
> else if(action == B)
> doB();
> else
> doC();
> 
> or , if it's really that clean, i'd probably go for
> if(action == A)  doA();
> else if(action == B)  doB();
> else doC();

No, that's not what I mean. It's not necessarily compression in the
sense that the coder is taking up less actual space. It's hard to
explain, and I'm not good at it because I try not to do it. It's more
along the lines of using very terse and peculiar coding techniques to
save time and look kewl. Maybe something like this:

The "long" way:

$alfa = 0;
if ($bravo) {
if ($delta)
$alfa = echo();
elseif ($foxtrot)
$alfa = golf();
}
elseif ($hotel) {
$alfa = india();
}

The "kewl" way would be to translate the above into a single expression
using solely multiple nested terniary operators ( ? : ) on a single line.
Nothing wrong with the functionality of the result, but it becomes hard
has hell to read and figure out what the code is trying to do. And
nothing against terniary operators. I use them where appropriate. But in
a complex conditional like the above, they really only serve to
obfuscate the meaning of the code. We might marvel at the skill of a
programmer who did such a thing, but he's obviously not looking down the
road at the other people who will later maintain his code.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-30 Thread Sebastian Krebs
Hi,

Just want to throw my 2 cent in :)

2012/5/30 Tony Marston 

>
> "Ashley Sheridan"  wrote in message
> news:1338326229.2616.31.camel@localhost.localdomain...
> > On Tue, 2012-05-29 at 17:06 -0400, Paul M Foster wrote:
> >
> >> On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote:
> >>
> >> > On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >> > >  A rule of thumb is no more than 50 lines per
> >> > > function, most much less. Back in the day when we didn't have nifty
> >> > > gui screens and an 24 line terminals (yay green on black!), if a
> >> > > function exceeded one printed page, it was deemed too long and
> marked
> >> > > for refactoring.
> >> >
> >> > I think the idea of setting an arbitrary limit on the number of lines
> >> > that a
> >> > function should contain is quite ludicrous and something which I will
> >> > completely ignore. If a function requires a hundred or more lines then
> >> > so be
> >> > it. The only reason to take a block of code and put it into its own
> >> > function
> >> > is when that code is likely to be called more than once so that it
> >> > conforms
> >> > to the DRY principle. If it is only ever used in one place then there
> >> > is no
> >> > point.
> >> >
> >> > The problems I have with creating lots of small used-only-once
> >> > functions is
> >> > as follows:
> >> > - you have to create a meaningful name for each function.
> >> > - all those functions should be arranged in alphabetical order within
> >> > their
> >> > containing file - having them in a random sequence makes it difficult
> >> > to
> >> > find the one you want.
> >>
> 
> >
> > And yeah, alphabetical order? Really?
>
> This is a throwback to my 3GL days when all components within a file were
> arranged in alphabetical sequence so that they were easier to find when you
> looked at the printed listing.
>
> > Group them by similarity, sure.
> > But today, with IDEs that will jump straight to functions and class
> > methods, and the good ol' find tool on every editor I've ever seen, is
> > sorting them alphabetically really necessary? Seems like a waste of time
> > that is likely not going to be done by fellow developers working on the
> > same codebase.
>
> I have never come across an IDE that jumps to a function when you click on
> its name, so how does it return to where you jumped from?
>

At least PhpStorm and Eclipse have a feature to return where you come from.
I haven't seen an IDE, that is _not_ able to jump to a functions or methods
source for a long time now.


>
> Rather than artificially reduce the size of a function to satisfy someone
> else's limited attention span I would rather use the scroll wheel on my
> mouse. Scrolling up or down within a single function is easier than
> searching/finding/jumping to a series of sub-functions which may exist at
> random locations within the same file.
>

If the functions were named properly you don't have to follow every
execution path to the deepest deep. Or do you reading PHPs C-source, just
because a wild "substr()" appeared? When you see a method "loadFromFile()"
and the IDE tells you, that it expects a $filename as parameter, why should
you jump there just to make sure, that the method loads something from a
file by the filename given as first parameter?


>
> I will only split a large function into sub-functions when it makes sense
> to
> do so, and not because some nerd cannot scan more than 20 lines at a time.
>

The question I ask myself is: Why ^should^ a scan more than 20 lines at a
time, if it is possible, to make it clearer, but another nerd decided, that
it is too much work (or whatever). Maybe it's may "attention span", but I'm
usually slightly bugged, when I have to read code monsters. Compared to a
book it's a kind of "One chapter in a single sentence".


Regards,
Sebastian



>
> --
> Tony Marston
>
> http://www.tonymarston.net
> http://www.radicore.org
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Re: Function size

2012-05-30 Thread Tony Marston

"Ashley Sheridan"  wrote in message 
news:1338326229.2616.31.camel@localhost.localdomain...
> On Tue, 2012-05-29 at 17:06 -0400, Paul M Foster wrote:
>
>> On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote:
>>
>> > On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
>> > >  A rule of thumb is no more than 50 lines per
>> > > function, most much less. Back in the day when we didn't have nifty
>> > > gui screens and an 24 line terminals (yay green on black!), if a
>> > > function exceeded one printed page, it was deemed too long and marked
>> > > for refactoring.
>> >
>> > I think the idea of setting an arbitrary limit on the number of lines 
>> > that a
>> > function should contain is quite ludicrous and something which I will
>> > completely ignore. If a function requires a hundred or more lines then 
>> > so be
>> > it. The only reason to take a block of code and put it into its own 
>> > function
>> > is when that code is likely to be called more than once so that it 
>> > conforms
>> > to the DRY principle. If it is only ever used in one place then there 
>> > is no
>> > point.
>> >
>> > The problems I have with creating lots of small used-only-once 
>> > functions is
>> > as follows:
>> > - you have to create a meaningful name for each function.
>> > - all those functions should be arranged in alphabetical order within 
>> > their
>> > containing file - having them in a random sequence makes it difficult 
>> > to
>> > find the one you want.
>>

>
> And yeah, alphabetical order? Really?

This is a throwback to my 3GL days when all components within a file were 
arranged in alphabetical sequence so that they were easier to find when you 
looked at the printed listing.

> Group them by similarity, sure.
> But today, with IDEs that will jump straight to functions and class
> methods, and the good ol' find tool on every editor I've ever seen, is
> sorting them alphabetically really necessary? Seems like a waste of time
> that is likely not going to be done by fellow developers working on the
> same codebase.

I have never come across an IDE that jumps to a function when you click on 
its name, so how does it return to where you jumped from?

Rather than artificially reduce the size of a function to satisfy someone 
else's limited attention span I would rather use the scroll wheel on my 
mouse. Scrolling up or down within a single function is easier than 
searching/finding/jumping to a series of sub-functions which may exist at 
random locations within the same file.

I will only split a large function into sub-functions when it makes sense to 
do so, and not because some nerd cannot scan more than 20 lines at a time.

-- 
Tony Marston

http://www.tonymarston.net
http://www.radicore.org




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-29 Thread Matijn Woudt
On Tue, May 29, 2012 at 11:06 PM, Paul M Foster  wrote:
> OMG in alpha order?! At best, I might group them together by function
> type, with some comment notation in the file. But not alpha order. I
> prefer not to have "forward declares" in my files, so I generally
> arrange functions so that those called by other functions later are
> defined before they're called. (Probably a holdover from my C days; PHP
> doesn't care.)
>
> No offense. I never even thought about arranging functions in
> alphabetical order. But I don't think I'd do it.
>

Like most of us on this list (I think), I agree with you that
alphabetical order really doesn't make any sense.

>> - when browsing through the code you have to keep jumping to another
>> function, and then returning to where you came from.
>>
>> I don't know about you, but I would rather use the scroll wheel on my mouse
>> than keep jumping from one position in the file to another.
>>
>> Another problem I have encountered in the past with such an idea is that it
>> encourages a stupid programmer to decrease the number of lines of code by
>> compressing as many statements as possible into a single line, which then
>> makes the code less easy to read and understand. This is much worse than
>> having more than 20 lines in a function.
>
> I think a lot of coders try to be kewler than the next 18 guys who are
> gonna have to look at the code, so they use a lot of "compression"
> techniques to reduce LOC. Plus, they're lazy. I'd rather see everything
> with lots of spaces and plenty of comments and blank lines. Especially
> since I'm sometimes that 18th guy to look at the code.
>
> Paul

Paul,

Are you stating here that compression is a bad thing?

That means you consider this nice:

if ( action == A )
{
doA();
}
else if (action == B )
{
doB();
}
else
{
doC();
}

Or perhaps flooded with comments that merely say the same as the code does?

I'd go for
if(action == A)
doA();
else if(action == B)
doB();
else
doC();

or , if it's really that clean, i'd probably go for
if(action == A)  doA();
else if(action == B)  doB();
else doC();

- Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-29 Thread Ashley Sheridan
On Tue, 2012-05-29 at 17:06 -0400, Paul M Foster wrote:

> On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote:
> 
> > On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> > >  A rule of thumb is no more than 50 lines per
> > > function, most much less. Back in the day when we didn't have nifty
> > > gui screens and an 24 line terminals (yay green on black!), if a
> > > function exceeded one printed page, it was deemed too long and marked
> > > for refactoring.
> > 
> > I think the idea of setting an arbitrary limit on the number of lines that a
> > function should contain is quite ludicrous and something which I will
> > completely ignore. If a function requires a hundred or more lines then so be
> > it. The only reason to take a block of code and put it into its own function
> > is when that code is likely to be called more than once so that it conforms
> > to the DRY principle. If it is only ever used in one place then there is no
> > point.
> > 
> > The problems I have with creating lots of small used-only-once functions is
> > as follows:
> > - you have to create a meaningful name for each function.
> > - all those functions should be arranged in alphabetical order within their
> > containing file - having them in a random sequence makes it difficult to
> > find the one you want.
> 
> OMG in alpha order?! At best, I might group them together by function
> type, with some comment notation in the file. But not alpha order. I
> prefer not to have "forward declares" in my files, so I generally
> arrange functions so that those called by other functions later are
> defined before they're called. (Probably a holdover from my C days; PHP
> doesn't care.)
> 
> No offense. I never even thought about arranging functions in
> alphabetical order. But I don't think I'd do it.
> 
> > - when browsing through the code you have to keep jumping to another
> > function, and then returning to where you came from.
> > 
> > I don't know about you, but I would rather use the scroll wheel on my mouse
> > than keep jumping from one position in the file to another.
> > 
> > Another problem I have encountered in the past with such an idea is that it
> > encourages a stupid programmer to decrease the number of lines of code by
> > compressing as many statements as possible into a single line, which then
> > makes the code less easy to read and understand. This is much worse than
> > having more than 20 lines in a function.
> 
> I think a lot of coders try to be kewler than the next 18 guys who are
> gonna have to look at the code, so they use a lot of "compression"
> techniques to reduce LOC. Plus, they're lazy. I'd rather see everything
> with lots of spaces and plenty of comments and blank lines. Especially
> since I'm sometimes that 18th guy to look at the code.
> 
> Paul
> 
> -- 
> Paul M. Foster
> http://noferblatz.com
> http://quillandmouse.com
> 


I agree there is a certain amount of "let's make this in a cool way so
the next guy is dazzled" but after they come across stuff from the guy
before them it's soon curbed!

And yeah, alphabetical order? Really? Group them by similarity, sure.
But today, with IDEs that will jump straight to functions and class
methods, and the good ol' find tool on every editor I've ever seen, is
sorting them alphabetically really necessary? Seems like a waste of time
that is likely not going to be done by fellow developers working on the
same codebase.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: Function size

2012-05-29 Thread Paul M Foster
On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote:

> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >  A rule of thumb is no more than 50 lines per
> > function, most much less. Back in the day when we didn't have nifty
> > gui screens and an 24 line terminals (yay green on black!), if a
> > function exceeded one printed page, it was deemed too long and marked
> > for refactoring.
> 
> I think the idea of setting an arbitrary limit on the number of lines that a
> function should contain is quite ludicrous and something which I will
> completely ignore. If a function requires a hundred or more lines then so be
> it. The only reason to take a block of code and put it into its own function
> is when that code is likely to be called more than once so that it conforms
> to the DRY principle. If it is only ever used in one place then there is no
> point.
> 
> The problems I have with creating lots of small used-only-once functions is
> as follows:
> - you have to create a meaningful name for each function.
> - all those functions should be arranged in alphabetical order within their
> containing file - having them in a random sequence makes it difficult to
> find the one you want.

OMG in alpha order?! At best, I might group them together by function
type, with some comment notation in the file. But not alpha order. I
prefer not to have "forward declares" in my files, so I generally
arrange functions so that those called by other functions later are
defined before they're called. (Probably a holdover from my C days; PHP
doesn't care.)

No offense. I never even thought about arranging functions in
alphabetical order. But I don't think I'd do it.

> - when browsing through the code you have to keep jumping to another
> function, and then returning to where you came from.
> 
> I don't know about you, but I would rather use the scroll wheel on my mouse
> than keep jumping from one position in the file to another.
> 
> Another problem I have encountered in the past with such an idea is that it
> encourages a stupid programmer to decrease the number of lines of code by
> compressing as many statements as possible into a single line, which then
> makes the code less easy to read and understand. This is much worse than
> having more than 20 lines in a function.

I think a lot of coders try to be kewler than the next 18 guys who are
gonna have to look at the code, so they use a lot of "compression"
techniques to reduce LOC. Plus, they're lazy. I'd rather see everything
with lots of spaces and plenty of comments and blank lines. Especially
since I'm sometimes that 18th guy to look at the code.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function size

2012-05-29 Thread Tony Marston
On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
>  A rule of thumb is no more than 50 lines per
> function, most much less. Back in the day when we didn't have nifty
> gui screens and an 24 line terminals (yay green on black!), if a
> function exceeded one printed page, it was deemed too long and marked
> for refactoring.

I think the idea of setting an arbitrary limit on the number of lines that a
function should contain is quite ludicrous and something which I will
completely ignore. If a function requires a hundred or more lines then so be
it. The only reason to take a block of code and put it into its own function
is when that code is likely to be called more than once so that it conforms
to the DRY principle. If it is only ever used in one place then there is no
point.

The problems I have with creating lots of small used-only-once functions is
as follows:
- you have to create a meaningful name for each function.
- all those functions should be arranged in alphabetical order within their
containing file - having them in a random sequence makes it difficult to
find the one you want.
- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my mouse
than keep jumping from one position in the file to another.

Another problem I have encountered in the past with such an idea is that it
encourages a stupid programmer to decrease the number of lines of code by
compressing as many statements as possible into a single line, which then
makes the code less easy to read and understand. This is much worse than
having more than 20 lines in a function.

Whether a file contains 10 functions of 100 lines each, or 100 functions of
10 lines each, you still end up with 1000 lines of code. If you do not have
the mental capacity to deal with a 100-line function then you are in the
wrong job.

-- 
Tony Marston

http://www.tonymarston.net
http://www.radicore.org




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function size

2012-05-25 Thread Tedd Sperling
On May 24, 2012, at 4:48 PM, tamouse mailing lists wrote:

> Yes, I think that is *exactly* the criterion-- not a mystery or an emergent 
> thing, really, was a pretty expicit reasoning--being able to see/scan the 
> entire function on one page (or now in one screenful) makes it much easier to 
> see what happens in the function, where blocks open/close, and it forces one 
> to break up code into logical units.

While it may be obvious to you, there is considerable study on the ways we 
perceive things -- this is just one we apparently take for granted ... at least 
now.

Cheers,

tedd


_
t...@sperling.com
http://sperling.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function size

2012-05-24 Thread Ashley Sheridan
On Thu, 2012-05-24 at 15:48 -0500, tamouse mailing lists wrote:

> On May 23, 2012 9:14 AM, "Tedd Sperling"  wrote:
> >
> > Hi gang:
> >
> > On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> > >  A rule of thumb is no more than 50 lines per
> > > function, most much less. Back in the day when we didn't have nifty
> > > gui screens and an 24 line terminals (yay green on black!), if a
> > > function exceeded one printed page, it was deemed too long and marked
> > > for refactoring.
> >
> > You hit upon a theory of mine -- and that is our functions grow in size
> up to our ability to view them in their totality. When our functions get
> beyond that limit, we tend to refactor and reduce.
> >
> > I know from the last several decades of programming, my functions have
> increased in number of lines. But, they have reached a limit that limit is
> generally about the number of lines I can read in half of my monitor's
> height. This of course, is dependent on monitor resolution, font-size, and
> how far I am sitting from the monitor. But I think this is a natural and
> physical limit that we don't normally recognize. I can cite studies that
> support my theory.
> >
> > It would be an interesting survey to ask programmers to review their code
> and provide the average number of lines in their functions AND how many
> lines of code their monitor's can display. In other words, look at your
> editor; count the number of lines your monitor can display; estimate the
> number of lines in your average function; and report the findings.  For
> example, mine is about half -- my monitor can display 55 lines of code and
> my average function is around 25 lines. YMMV.
> >
> > Interesting, yes?
> >
> > Cheers,
> >
> > tedd
> >
> >
> > _
> > tedd.sperl...@gmail.com
> > http://sperling.com
> >
> >
> >
> >
> >
> 
> Yes, I think that is *exactly* the criterion-- not a mystery or an emergent
> thing, really, was a pretty expicit reasoning--being able to see/scan the
> entire function on one page (or now in one screenful) makes it much easier
> to see what happens in the function, where blocks open/close, and it forces
> one to break up code into logical units.


With the odd exception being where code is more readable in a longer
format, as seen with my and several others examples of long functions
that rely heavily on switches. 

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: Function size

2012-05-24 Thread tamouse mailing lists
On May 23, 2012 9:14 AM, "Tedd Sperling"  wrote:
>
> Hi gang:
>
> On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >  A rule of thumb is no more than 50 lines per
> > function, most much less. Back in the day when we didn't have nifty
> > gui screens and an 24 line terminals (yay green on black!), if a
> > function exceeded one printed page, it was deemed too long and marked
> > for refactoring.
>
> You hit upon a theory of mine -- and that is our functions grow in size
up to our ability to view them in their totality. When our functions get
beyond that limit, we tend to refactor and reduce.
>
> I know from the last several decades of programming, my functions have
increased in number of lines. But, they have reached a limit that limit is
generally about the number of lines I can read in half of my monitor's
height. This of course, is dependent on monitor resolution, font-size, and
how far I am sitting from the monitor. But I think this is a natural and
physical limit that we don't normally recognize. I can cite studies that
support my theory.
>
> It would be an interesting survey to ask programmers to review their code
and provide the average number of lines in their functions AND how many
lines of code their monitor's can display. In other words, look at your
editor; count the number of lines your monitor can display; estimate the
number of lines in your average function; and report the findings.  For
example, mine is about half -- my monitor can display 55 lines of code and
my average function is around 25 lines. YMMV.
>
> Interesting, yes?
>
> Cheers,
>
> tedd
>
>
> _
> tedd.sperl...@gmail.com
> http://sperling.com
>
>
>
>
>

Yes, I think that is *exactly* the criterion-- not a mystery or an emergent
thing, really, was a pretty expicit reasoning--being able to see/scan the
entire function on one page (or now in one screenful) makes it much easier
to see what happens in the function, where blocks open/close, and it forces
one to break up code into logical units.


[PHP] Re: function

2012-05-04 Thread Jim Giner
""Ron Piggott""  wrote in message 
news:499A66F0FB394E1DB44F7E0C011CF11C@RonPiggottPC...
I need to access a FUNCTION I programmed within a different FUNCTION.  Are 
these able to be passed like a variable?  Or are they able to become like a 
$_SESSION variable in nature?  How am I able to do this?

Why not just separate the functions?  Then you won't have any problem like 
that.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: function within a class function

2010-06-21 Thread Gary .
On Mon, Jun 21, 2010 at 10:49 AM, Pete Ford wrote:
> On 21/06/10 00:45, Rick Pasotto wrote:

> I think that's right - doesn't the manual describe this sort of thing about
> using callback functions that are class members?

Yes. 
http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function within a class function

2010-06-21 Thread Pete Ford

On 21/06/10 00:45, Rick Pasotto wrote:

Within a class function I have defined another function for use with the
usort() function. How do I reference it?

When it's not part of a class usort($arr,"cmp") works fine but when it's
within a class function I get this error:

PHP Parse error:  syntax error, unexpected T_STRING, expecting T_FUNCTION

Is it not in the scope of the class function?



you need to use an array to describe the callback function:

class Foo
{
public function cmp($a,$b)
{
// do comparison and return result
}
}

then

$foo = new Foo();
usort($arr,Array($foo,'cmp'));



I think that's right - doesn't the manual describe this sort of thing about 
using callback functions that are class members?



--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function parameters and arrays

2008-09-18 Thread Frank Stanovcak
Actually Stut pointed out that I was calling both dimmensions when my sorry 
butt should only have been referencing the second one.
I had everything over expanded so I could see where the code was breaking.
Thank you everyone for the help!  That was fantastic!

Frank
""Frank Stanovcak"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am trying to pass a multi dimmed array as a variable parameter to a 
>custom function to build a query for me.  Here is the basic code and what I 
>am getting.
>
> $WhereList[0][0] = 'OESalesOrder.OrderNo';
> $WhereList[0][1] = '=';
> $WhereList[0][2] = '2272';
> $SQLString = SQLCall('OESalesOrder',$FieldList,$WhereList);
>
> I then use a foreach in the function to process it.
>
> $i = 0;
>  foreach(func_get_arg(2) as $WhereArray) {
>   echo $WhereArray[0][0];
>   if($i == 0) {
>$SQLStmt .= ' ' . $WhereArray[$i][0] . ' ' . $WhereArray[$i][1] . ' ' . 
> $WhereArray[$i][2];
>$i += 1;
>   } else {
>$SQLStmt .= ' ' . $WhereArray[$i][0] . ' ' . $WhereArray[$i][1] . ' ' . 
> $WhereArray[$i][2] . ' ' . $WhereArray[$i][3];
>$i += 1;
>   };
>  };
>
> What I get when it processes is the first three letters of [0][0]
> [0][0] = O
> [0][1] = E
> [0][2] = S
>
> Did I do something wrong, or is this not possible?  I have done an array 
> processing this way before, but not multidimmed.
>
> Frank.
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function-return-array idea

2008-01-16 Thread Shawn McKenzie
I'm sure I'm a pea-brain, but this caught my attention.

So you execute the fetchObjects() method which could return a large
number of objects, then you reference a method of the 0th one.

I didn't test, but why not use: $object->fetchObjects(0)->method();

Where fetchObjects($id) returns the object referenced by $id instead of all?

-Shawn

echo $object->fetchObjects()[0]->method();

Stijn Leenknegt wrote:
> Hello
> 
> I've an idea for PHP6. Let's kickoff with an example.
> 
>  $info = getUserInformation($id); //return an array with all the information
> of an user.
> echo $info['naam'];
> ?>
> 
> This is nice, but when I want one element of the returned array, I have to
> store the returned array into a variable and then call the variable.
> The next code example is my idea.
> 
>  echo getUserInformation($id)['naam'];
> ?>
> 
> Let's look further then this small example.
> 
>  echo $object->fetchObjects()[0]->method();
> ?>
> 
> This example is more realistic when you use OO. This code style is faster
> for developing applications. This code style is available in Java,
> Javascript, C, C++, Perl, Python, ... So why not in PHP(6)? You can read
> more on my blog.
> 
> http://www.eos-team.org/2007/09/06/php6-function-return-array-idea.html
> 
> I hope for good response and also response from php-dev team.
> 
> Greetings
> Stijn Leenknegt
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-02 Thread Jochem Maas
Paul van Haren wrote:
> OK guys, thanks for all your inputs. 
> 
> Based on your guidance, I have tested the following code with a
> series of variations: 
> 
>   class foobar {
>   function bar2 () {
>   echo "Yep, in bar2() right now\n";
>   }
> 
>   public function foo2 () {
>   $a = "bar2";// Experiment 0
>   $a();   // Fatal error
>   }
>   }
> 
> And the variations:
>   $a = "bar2";// Experiment 0
>   $a();   // Fatal error: Call to undefined function 
> bar2()
> 
>   $a = "foobar::bar2";// Experiment 1
>   $a();   // Fatal error: Call to undefined function 
> bar2()
> 
>   $a = "bar2";// Experiment 2
>   eval($a."();"); // Fatal error: Call to undefined function 
> bar2()
> 
>   $a = "foobar::bar2";// Experiment 3
>   eval($a."();"); // Works but far from elegant
> 
>   $a = "bar2";// Experiment 4
>   $this->$a();// Works fine
> 
>   $a = "bar2";// Experiment 5
>   self::$a(); // Works fine
> 
> So, I have a working solution right now. But I still don't understand the
> essence of the differences between experiment #1 and #4. Also, I don't
> understand the need to specify the class name in experiment #3, coming
> from #2. Functions bar2() and foo2() are part of the same class foobar,
> and I would assume that the name 'bar2' would be in scope of the function
> foo2.

your assumptions and php's reality differ. symbol names resolution is never
tired in the class scope.

$a = "foobar::bar2";
$a();

this is trying to call a function called "foobar::bar2", which given that
you cant do (parse error):

function foobar::bar2() {}

whatever munged error message you get regarding 'bar2()' not existing,
the fact remains that 'variable' function name functionality has no concept
of class scope, the T_PAAMAYIM_NEKUDOTAYIM is not recognized. never has been,
probably never will be.

class foo {
function bar1() {
$a = "foo::bar2";   
call_user_func(explode("::",$a));
}

static function bar2() {
echo __METHOD__,"\n";
}
}

$foo = new foo; $foo->bar1();


having no idea what it is that your actually trying to achieve, it's hard
to tell whether any percieved limitation is justified.

you might consider taking a look at reflection:

http://nl2.php.net/reflection


> 
> BTW: I'm running PHP v5.2.0-8 build and distributed by Debian (etch1).
> 
> Thanks again and regards, Paul.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Paul van Haren
OK guys, thanks for all your inputs. 

Based on your guidance, I have tested the following code with a
series of variations: 

class foobar {
function bar2 () {
echo "Yep, in bar2() right now\n";
}

public function foo2 () {
$a = "bar2";// Experiment 0
$a();   // Fatal error
}
}

And the variations:
  $a = "bar2";// Experiment 0
  $a();   // Fatal error: Call to undefined function bar2()

  $a = "foobar::bar2";// Experiment 1
  $a();   // Fatal error: Call to undefined function bar2()

  $a = "bar2";// Experiment 2
  eval($a."();"); // Fatal error: Call to undefined function bar2()

  $a = "foobar::bar2";// Experiment 3
  eval($a."();"); // Works but far from elegant

  $a = "bar2";// Experiment 4
  $this->$a();// Works fine

  $a = "bar2";// Experiment 5
  self::$a(); // Works fine

So, I have a working solution right now. But I still don't understand the
essence of the differences between experiment #1 and #4. Also, I don't
understand the need to specify the class name in experiment #3, coming
from #2. Functions bar2() and foo2() are part of the same class foobar,
and I would assume that the name 'bar2' would be in scope of the function
foo2.

BTW: I'm running PHP v5.2.0-8 build and distributed by Debian (etch1).

Thanks again and regards, Paul.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Robert Cummings
On Thu, 2007-11-01 at 17:16 +0100, Jochem Maas wrote:
> Robert Cummings wrote:
> > On Thu, 2007-11-01 at 16:10 +0100, Jochem Maas wrote:
> >> I've completely lost track of the state of the exact OO rules in any
> >> given version of php5)
> > 
> > Haha, you too eh!?
> > 
> > BTW, I finally bothered to download PHP 5.2.4 last night and checked it
> > out. This is the first time I've seen a speed improvement over PHP4 for
> > my work. Most of my pages gained a 10% to 20% load time improvement. One
> > thing that was odd though was when I built a few sites from the shell
> > using InterJinn's template engine, the time spent doubled. So I guess I
> > win some and lose some :) Page load time is more important since I don't
> > often build whole sites from scratch. Still perplexing though what could
> > have slowed down so much... I'll have to dig into it with a profiler
> > sometime when I have more free time.
> 
> interesting info - thanks for the heads up.

Yeah, I'm going to make it my default development version now :)

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Jochem Maas
Robert Cummings wrote:
> On Thu, 2007-11-01 at 16:10 +0100, Jochem Maas wrote:
>> I've completely lost track of the state of the exact OO rules in any
>> given version of php5)
> 
> Haha, you too eh!?
> 
> BTW, I finally bothered to download PHP 5.2.4 last night and checked it
> out. This is the first time I've seen a speed improvement over PHP4 for
> my work. Most of my pages gained a 10% to 20% load time improvement. One
> thing that was odd though was when I built a few sites from the shell
> using InterJinn's template engine, the time spent doubled. So I guess I
> win some and lose some :) Page load time is more important since I don't
> often build whole sites from scratch. Still perplexing though what could
> have slowed down so much... I'll have to dig into it with a profiler
> sometime when I have more free time.

interesting info - thanks for the heads up.

> 
> Cheers,
> Rob.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Robert Cummings
On Thu, 2007-11-01 at 16:10 +0100, Jochem Maas wrote:
> I've completely lost track of the state of the exact OO rules in any
> given version of php5)

Haha, you too eh!?

BTW, I finally bothered to download PHP 5.2.4 last night and checked it
out. This is the first time I've seen a speed improvement over PHP4 for
my work. Most of my pages gained a 10% to 20% load time improvement. One
thing that was odd though was when I built a few sites from the shell
using InterJinn's template engine, the time spent doubled. So I guess I
win some and lose some :) Page load time is more important since I don't
often build whole sites from scratch. Still perplexing though what could
have slowed down so much... I'll have to dig into it with a profiler
sometime when I have more free time.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Nathan Nobbe
On 11/1/07, Jochem Maas <[EMAIL PROTECTED]> wrote:
>
> Sebastian Hopfe wrote:
> > I think you should log it, because it seems to be, and you found this
> > error.
>
> it's not a bug - especially because nobody has bothered to mention the php
> version.


this issue has the same implications in php4 and php5, because its about
variable functions
and phps inability to resolve class names or references from the contents of
a variable
when the variable is used in the context of a class method invocation.

I'm guessing that it's being run on a version php5, in which case the fatal
> error
> seems correct - you have a non-static method defined and then you are
> trying to
> call that method statically which is not allowed (IIRC whether this works
> or not
> depends on the minor version of php5 your running - something the
> OO-purism gang
> forced on us, actually the restriction may have been removed again - I've
> completely
> lost track of the state of the exact OO rules in any given version of
> php5)


i dont know what the version granularity is either regarding the use of
static class methods
being invoked when the methods are not declared static.  i dont think ive
ever seen a fatal
error raised for that, and at any rate, the error clearly indicates that it
pertains to the misuse
of static method, in that case, which is not the case in the error message
reported earlier.

Error raised when invoking a method not defined as static from a static
context:
(5.2.4-pl2-gentoo)
Strict standards: Non-static method Foo::nonStaticMethod() should not be
called statically in
/home/nathan/workspace/sacd/svn/itc-dev/testStaticCall2.php on line 14

(original error message from this thread)
Fatal error: Call to undefined function foobar::bar2() in
/home/paul/demo/demo.php on line 25

this strengthens the case that i made earlier, namely this issue is a result
of phps lack of
resolving class names and references when they are embedded in a string that
is used as
a variable function.

here is a code fragment to test the static method calls out against any
version of php5.

staticMethod();
$foo->nonstaticMethod();
?>

on php 5.2.4 you will have to enable E_STRICT to see the warning.

error_reporting  =  E_ALL | E_STRICT

-nathan


Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Jochem Maas
Sebastian Hopfe wrote:
> I think you should log it, because it seems to be, and you found this
> error.

it's not a bug - especially because nobody has bothered to mention the php 
version.

I'm guessing that it's being run on a version php5, in which case the fatal 
error
seems correct - you have a non-static method defined and then you are trying to
call that method statically which is not allowed (IIRC whether this works or not
depends on the minor version of php5 your running - something the OO-purism gang
forced on us, actually the restriction may have been removed again - I've 
completely
lost track of the state of the exact OO rules in any given version of php5)

> 
> Regard
> Sebastian
> 
> "Paul van Haren" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]
>> Thanks, this helps. The code now works.
>> In case this is truely a bug in PHP, where should I log it? Anything that
>> I should do to make sure that it gets followed up?
>>
>> Regards, Paul 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function variables in classes

2007-11-01 Thread Nathan Nobbe
On 11/1/07, Sebastian Hopfe <[EMAIL PROTECTED]> wrote:
>
> I think you should log it, because it seems to be, and you found this
> error.


i would not consider this a bug.
what paul is asking about is the variable function syntax in php.
http://www.php.net/manual/en/functions.variable-functions.php

whats happening is php is not resolving the first portion of the variable
contents
to a class name, nor is it capable of resolving the scope resolution syntax
when
dynamically evaluating a variable contents in the context of a method call.
there is no mention of such support in the manual.

consider this fragament (it will not work)
class DynamicMethodCaller {
public function memFunc() {
echo __METHOD__ . PHP_EOL;
}

public function invoker($dynamicMethod) {
$dynamicMethod();
}
}

$instance = new DynamicMethodCaller();
$instance->invoker('$this->memFunc');


now consider this revision (which works perfectly)
class DynamicMethodCaller {
public function memFunc() {
echo __METHOD__ . PHP_EOL;
 }

public function invoker($dynamicMethod) {
$this->$dynamicMethod();
 }
 }

$instance = new DynamicMethodCaller();
$instance->invoker('memFunc');


the only difference between this fragment and the one
originally posted is the use of static member functions in the
original post.  here are 2 fragments showing what works
and what doesnt when working with static class member functions

(doest work)
class DynamicMethodCaller {
static public function memFunc() {
echo __METHOD__ . PHP_EOL;
 }

public function invoker($dynamicMethod) {
$dynamicMethod();
 }
 }

$instance = new DynamicMethodCaller();
$instance->invoker('DynamicMethodCaller::memFunc');

(works)
class DynamicMethodCaller {
public function memFunc() {
echo __METHOD__ . PHP_EOL;
 }

public function invoker($dynamicMethod) {
self::$dynamicMethod();
 }
 }

$instance = new DynamicMethodCaller();
$instance->invoker('memFunc');

in general the use of eval() should be avoided unless absolutely necessary.
in this case it is not necessary; just use the syntax supported by the
interpreter
and youre good to go.

-nathan


[PHP] Re: Function variables in classes

2007-11-01 Thread Sebastian Hopfe

I think you should log it, because it seems to be, and you found this error.

Regard
Sebastian

"Paul van Haren" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

Thanks, this helps. The code now works.
In case this is truely a bug in PHP, where should I log it? Anything that
I should do to make sure that it gets followed up?

Regards, Paul 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function variables in classes

2007-11-01 Thread Paul van Haren
Thanks, this helps. The code now works. 
In case this is truely a bug in PHP, where should I log it? Anything that
I should do to make sure that it gets followed up?

Regards, Paul

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function variables in classes

2007-11-01 Thread Sebastian Hopfe

It seems to be a PHP Bug, because normaly it should very well.

but you can solve this problem, by a workarround.

using "eval($a."();");" instead of "$a();" in the class.

Best regards
Sebastian


"Paul van Haren" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

Hi there,

I'm trying to execute function variables. This works fine outside class
code, but gives a fatal error when run within a class. The demo code is
here:

foo2();
?>

The error message reads:
Fatal error: Call to undefined function
foobar::bar2() in /home/paul/demo/demo.php on line 25

Is there anyone out there who can explain what's wrong in this code?

Thanks, Paul 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function -> action

2007-08-03 Thread Daniel Macedo

Ralph Kutschera escreveu:

Hallo!

  I'm working on a project, where we distinguish between "functions" and
"actions" in design, although in PHP both are implemented as functions.
Is there a chance that PHP can use the word "action" as "function"?

E.g.:
public function doSomething() {  }
public action doSomethingElse() { ... }

... is actually the same but would help to see the design also in the code.

TIA, Ralph


That's not implemented in PHP language.

What you should do is use adequate naming conventions, use verbs and as 
far as possible, describe what the function does:


public function execute_someaction() {}
public function sanitize_somedata() {}
public function is_validwhatever() {}

Can you understand what each function does by their names? What should 
they return? How about in your application(s)...


~ DM

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function Overloading

2005-12-18 Thread joshua may

Labunski wrote:

"PHP does not support function overloading."
So, is there any other way of getting a number of parameters(variables) 
passed to a function?


aka.
function fruits($apple, $banana, $kiwi, $grape){

#should (somehow) output 4

}

OK. if it was an array, than I could use count($array), but now I'm stuck!

Thanks in advance! 


func_num_args() will do the trick.

and then you use func_get_arg() or func_get_args() to use them.

http://au2.php.net/func_num_args

--josh

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function 'another_mail' with authentication

2005-10-24 Thread Manuel Lemos

Hello,

on 10/24/2005 10:57 PM Etienne Finet said the following:

Can anyone give me a clue on how to change this script so it can be used
with basic SMTP authentication?


SMTP authentication is not that simple. There are several authentication 
methods and you need to establish an authentication dialog according to 
what authentication methods your SMTP server supports.


You may want to take a look at this class that provides a wrapper 
function named smtp_mail similar to the one that you wrote, except that 
it also implements authentication as you need.


http://www.phpclasses.org/mimemessage

You also need this class for the SMTP dialog:

http://www.phpclasses.org/smtpclass

And this class for the authentication support:

http://www.phpclasses.org/sasl

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function MAX with WHERE

2005-07-25 Thread Mark Rees
"Jesús Alain Rodríguez Santos" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have someting like this:
>
> $test = mysql_query("SELECT MAX(dato) AS datos FROM tabla WHERE campo_mes
> = '$mes'");
> $test_m = mysql_fetch_array($test);
> $test_mes = $test_m['datos'];
>
> print $test_mes
>
> where $mes is a value
> I need to know if something its wrong, because I don't recive any error,
> but I see nothing

Try this, it will tell you if something is wrong

echo  mysql_error();

If nothing is wrong, then perhaps your query returns no rows? Test this by
removing the where clause (assuming there is some data in tabla).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: function problem

2005-01-03 Thread Richard Lynch
If you were trying to use the result from mysql_pconnect() as the second
optional argument to mysql_query() in your function, be sure you declare
it 'global' inside the function.

Read PHP docs on "variable scope" if this is what tripped you up.

If not, I have no idea why the database is not selected, but you can now
focus on figuring out where/when it got selected, and where/when it got
un-selected, and there may even be a query you could send to ask MySQL
what database it thinks you are using.  Sprinkle a lot of those through
your code to find out where it changes from what you expect to "not
working"

Viktor Popov wrote:
> Hi,
>
> Thank you for your reply!
>
> I have changed the function like this:
>
> function doReg($fname1="",$family1="",$company1="", $MOL1="", $dannum1="",
> $bulstat1="", $phone1="", $email1="", $username1="", $password1="",
> $payment1="", $maillist1="", $Addr1="", $City1="", $zipcode1="",
> $Country1="", $shippingName1="", $shippingFamily1="", $shippingphone1="",
> $shippingAddr1="", $shippingcity1="", $shippingzipcode1="",
> $shippingCountry1="")
> {
>
>   mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or
> die(mysql_error());
>
>
>
>  mysql_select_db($DB) or die(mysql_error());
>   mysql_query( "insert into users(name,family,company, MOL, taxnum,
> bulstat,
> phone, email, username, password, payment, maillist, Addr, City, zipcode,
> Country, shippingName, shippingFamily, shippingphone, shippingAddr,
> shippingcity, shippingzipcode, shippingCountry)
> values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
> '$phone1', '$email1', '$username1', '$password1', '$payment1',
> '$maillist1',
> '$Addr1', '$City1', '$zipcode1',
> '$Country1','$shippingName1','$shippingFamily1',
> '$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
> '$shippingCountry1')") or die (mysql_error());
>
>
> }
>
> I think that the problem is not in the insertion string because when write
> the function body :
>  mysql_pconnect(.);
> mysql_select_db($DB) or die(mysql_error());
> mysql_query("insert into ");
>
> instead doReg() in register.php, everything works. I have inserted some
> data
> in this way.
> The problem is that A DATABASE is  NOT SELECTED. This is the message when
> I
> use doReg().
>
> The register.php   is   in the DOCROOT->emagazine.  In the subdirectory
> script are "common.inc"  and  "functions.php". In common.inc is this:
>
>   $DB_SERVER="localhost";
>  $DB_LOGIN="admin";
>  $DB_PASSWORD="**";
>  $DB="emagazine";
>  $HTTP_HOST="localhost:3000";
>  $DOCROOT="emagazine";
>
> ?>
>
> Is it all right? I think that $DB="emagazine"  should work. Here I select
> the $DB, which name is "emagazine".
>
> I don't understand what's going on:)
>
>
>
> Thank you!
>
> Viktor
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function problem

2005-01-03 Thread Viktor Popov
Hi,

Thank you for your reply!

I have changed the function like this:

function doReg($fname1="",$family1="",$company1="", $MOL1="", $dannum1="",
$bulstat1="", $phone1="", $email1="", $username1="", $password1="",
$payment1="", $maillist1="", $Addr1="", $City1="", $zipcode1="",
$Country1="", $shippingName1="", $shippingFamily1="", $shippingphone1="",
$shippingAddr1="", $shippingcity1="", $shippingzipcode1="",
$shippingCountry1="")
{

  mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or
die(mysql_error());



 mysql_select_db($DB) or die(mysql_error());
  mysql_query( "insert into users(name,family,company, MOL, taxnum, bulstat,
phone, email, username, password, payment, maillist, Addr, City, zipcode,
Country, shippingName, shippingFamily, shippingphone, shippingAddr,
shippingcity, shippingzipcode, shippingCountry)
values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
'$phone1', '$email1', '$username1', '$password1', '$payment1', '$maillist1',
'$Addr1', '$City1', '$zipcode1',
'$Country1','$shippingName1','$shippingFamily1',
'$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
'$shippingCountry1')") or die (mysql_error());


}

I think that the problem is not in the insertion string because when write
the function body :
 mysql_pconnect(.);
mysql_select_db($DB) or die(mysql_error());
mysql_query("insert into ");

instead doReg() in register.php, everything works. I have inserted some data
in this way.
The problem is that A DATABASE is  NOT SELECTED. This is the message when I
use doReg().

The register.php   is   in the DOCROOT->emagazine.  In the subdirectory
script are "common.inc"  and  "functions.php". In common.inc is this:



Is it all right? I think that $DB="emagazine"  should work. Here I select
the $DB, which name is "emagazine".

I don't understand what's going on:)



Thank you!

Viktor

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function problem

2005-01-03 Thread Viktor Popov
Hi, thank you for your reply! I'll consider carefully this holes. Thank you!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function problem

2005-01-02 Thread Greg Beaver
Hi Viktor,
Viktor Popov wrote:
Hi,
I'm trying to do the following but I don't have any success. Could you help
me here...
I have this code in mu page:

if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
  $$key = $value;
}
This is a huge security hole, far better is to do this:
if (isset ($_POST['submit'])) {
foreach (array('field1', 'field2', 'field3') as $allowedfield) {
if (isset($_POST[$allowedfield])) {
$$allowedfield = $_POST[$allowedfield];
}
}
}
In addition, you really need to use mysql_escape_string() to avoid 
serious potential problems with sql injection attacks.

[NOTE: mysql_db_query() is deprecated, use mysql_query()/mysql_select_db()]
mysql_select_db($DB);
mysql_query('INSERT INTO blahbalhblahblah VALUES("' . 
mysql_escape_string($field1) . '" ');

Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: function problem

2004-09-04 Thread Andre Dubuc
On Saturday 04 September 2004 03:42 pm, Torsten Roehr wrote:
> "Matthias Bauw" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > I'm having a problem with a php application;
> >
> > I have two files: one is ccadduser wich adds users to a controlcenter
> > that I am currently designing for a website.
> >
> > In that ccaduserfile I call for a function checkpermission(); this
> > function is defined in another file called ccfunctions
> >
> > When a user does not have access to the script it should abort the
> > script, this is done using a header("location: ccnopermission.php");
> > statement
> >
> > But now it seems that while executing the function checkpermission()
> > the code in ccadduser just keeps running and the database query that
> > inserts the new user is executed before the user can be redirected to
> > ccnopermission.
> >
> > Is there a way to make php wait until checkpermission is completely
>
> executed?
>
> > I know it is not a simple question, but I really need a solution to
> > ensure the safety of my system.
> >
> > grtz & thanks
> >
> > DragonEye
>
> I'm not completely sure if I understand your question but PHP will process
> one function after the other. Without seeing some code I'm afraid we can't
> help you much.
>
> Regards, Torsten Roehr


Two thoughts:

You call function checkpermission(); that is defined in another file. How do 
you call this file: do you use absolute url? Might be the problem, as well as 
using header("location; ccnopermissions.php");. Might want to use an absolute 
url there too.

Just a thought or two,
Andre

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function problem

2004-09-04 Thread Torsten Roehr
"Matthias Bauw" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm having a problem with a php application;
>
> I have two files: one is ccadduser wich adds users to a controlcenter
> that I am currently designing for a website.
>
> In that ccaduserfile I call for a function checkpermission(); this
> function is defined in another file called ccfunctions
>
> When a user does not have access to the script it should abort the
> script, this is done using a header("location: ccnopermission.php");
> statement
>
> But now it seems that while executing the function checkpermission()
> the code in ccadduser just keeps running and the database query that
> inserts the new user is executed before the user can be redirected to
> ccnopermission.
>
> Is there a way to make php wait until checkpermission is completely
executed?
>
> I know it is not a simple question, but I really need a solution to
> ensure the safety of my system.
>
> grtz & thanks
>
> DragonEye

I'm not completely sure if I understand your question but PHP will process
one function after the other. Without seeing some code I'm afraid we can't
help you much.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function Get Error

2004-09-03 Thread Torsten Roehr
>"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>I write this function to delete directory and file but when i 've a
directory not empty i get error
>The code that i write is this:
>
>I receive this warning:
>Warning: rmdir(cartella): Directory not empty in c:\programmi\apache
group\apache\users\test\project\delete.php on line 23
>I have set chmod on linux chmod to 777 but i can delete folder only when is
empty.
>What I do ?
>Thanks to all and sorry for my bad language.

I guess you'll first have to delete all files in the directory. Try this
function:


/**
 * Recursively clear a local directory
 *
 * @param string  $sourceDirdirectory to delete
 * @param integer $leveldirectory level (to avoid deleting the
root dir)
 */
function clearDirectory($sourceDir, $level = 0)
{
// proceed if source directory exists
if  (is_dir($sourceDir))
{
// read dir contents
if  ($handle = opendir($sourceDir))
{
   /* This is the correct way to loop over the
directory. */
   while(false !== ($dirItem = readdir($handle)))
{
if  ($dirItem != '.' && $dirItem !=
'..')
{
// directory
if  (is_dir($sourceDir . '/'
. $dirItem))
{

clearDirectory($sourceDir . '/' . $dirItem, $level + 1);
}
// file
elseif  (file_exists($sourceDir
. '/' . $dirItem))
{
unlink($sourceDir .
'/' . $dirItem);
}
}
}

// remove directory if it's not the root one
if  ($level > 0)
{
rmdir($sourceDir);
}
}

closedir($handle);
}
}

It will delete all direcotries and files *inside* the specified directory.
So the directory itself will not be deleted.

Just call it like this (without trailing shlash!!!):

clearDirectory('/path/to/directory');


Hope it works for you.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function Problem

2004-09-01 Thread Jasper Howard
the checkpermission(); function should be run before php can pharse anything
farther down the script, try putting an exit; after the header() statement.

-- 


-->>
Jasper Howard :: Database Administration
Velocity7
1.530.470.9292
http://www.Velocity7.com/
<<--
"Matthias Bauw" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm having a problem with a php application;
>
> I have two files: one is ccadduser wich adds users to a controlcenter
> that I am currently designing for a website.
>
> In that ccaduserfile I call for a function checkpermission(); this
> function is defined in another file called ccfunctions
>
> When a user does not have access to the script it should abort the
> script, this is done using a header("location: ccnopermission.php");
> statement
>
> But now it seems that while executing the function checkpermission()
> the code in ccadduser just keeps running and the database query that
> inserts the new user is executed before the user can be redirected to
> ccnopermission.
>
> Is there a way to make php wait until checkpermission is completely
executed?
>
> I know it is not a simple question, but I really need a solution to
> ensure the safety of my system.
>
> grtz & thanks
>
> DragonEye

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function Mail

2004-08-08 Thread Torsten Roehr
"Juan Pablo Herrera" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi everybody,
> I have a cuestion about the features on function mail. I think that it
> send the email one to one address. Is it ok?.
> Regards,
> Juan Pablo

Hi Juan Pablo,

the manual says:

"mail() automatically mails the message specified in message to the receiver
specified in to . Multiple recipients can be specified by putting a comma
between each address in to."

This should answer your question. Otherwise take a look at the manual page:
http://de2.php.net/manual/en/function.mail.php

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function that creates a class instance with a given name

2004-06-29 Thread Maris
Found the solution:

function create_car($params){
 global $smarty;
 $car = new Car("Jeep sWrangler","black");
 $smarty->register_object($params[id], $car);

}




"Maris" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi there!
>
> I am trying to make a PHP function "create_object" that would allow me to
> create a class instance with supplied name
>
> Here's the Smarty code snipset I would like to use my function in:
>
> {* Let's create a new class object with name "car" *}
> {create_object id=$id_car name="car"}
>
> {* When it is created, we can print out its properties or do whatever we
> need to *}
> The brand is: {$car->brand}
> and car's color is: {$car->color}
>
>
>
> Any ideas how to create PHP function that would allow to create the
instance
> so I can
> operate with it in Smarty as shown above?
>
> function create_object($id, $name){
>//help needed
> }
>
>
> Thanks,
> Maris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function for string to array (map)?

2004-06-18 Thread Aidan Lister
No, because that's not a standard format.

You'll have to write your own function (as you've done).

If you're looking to store an array as a string, look at serialize()

"Pete Forman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is there a standard function that converts a string to an array with
> proper keys, not auto generated integers?  I've found myself calling
> explode() twice.  split(), etc. do not seem to offer any improvement.
>
> $str = "a:x,b:y,c:z";
> $arr = explode(",", $str);
> foreach ($arr as $item) {
>   list($key, $value) = explode(":", $item);
>   $map[$key] = $value;
> }
>
> Is there a foo() that would do something like this?
>
> $map = foo(",", ":", $str);
>
> -- 
> Pete Forman-./\.-  Disclaimer: This post is originated
> WesternGeco  -./\.-   by myself and does not represent
> [EMAIL PROTECTED]-./\.-   opinion of Schlumberger, Baker
> http://petef.port5.com   -./\.-   Hughes or their divisions.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function for backing up mysql

2004-04-14 Thread Kim Steinhaug
Take a look at phpclasses.org
Last week there also came another class especially made for backups aswell
if I recall.

-- 
-- 
Kim Steinhaug
--
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
--
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
--

"Victor spång arthursson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi!

Wonder if anyone knows if there somewhere "out there" are any good
functions that streams out data from mysql as a sql-file, like
phpmyadmin does?

The best would be one which I told which database and which tables to
dump, and which directly stared streaming the data…

Sincerely

Victor=

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: function imagecreatefromjpeg pb

2004-04-11 Thread Cosas minovela





about GD, Warning: imagecreatefromjpeg(): 
'/var/www/html/datos/2004/02/crio25.jpg' is not a valid JPEG file. how can i 
solve it please?
 
image pass the EOF and BOF test, so this is not the 
problem :)
 
here you got the image with problems , i'm sorry 
about the content of image...
 
http://www.paginadespud.com/datos/2004/02/crio25.jpg
 
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Re: Function to check a valid date

2004-03-20 Thread Tom Reed
Try this:
http://us4.php.net/checkdate

-Tom Reed
[EMAIL PROTECTED]

"Chris Bruce" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello all,

I was going to build a function to check whether a selected date
exists, but thought that I would see if anyone has done this type of
thing already which would indeed save me some time.

I have a form where the users select the day of the week, month, date
and year from 4 pulldowns. (Saturday, March 20, 2004). I need to have a
function that will check to see if that is indeed a real date.

Does this sound familiar to anyone?

Thanks a bunch :)

--

Chris Bruce
[EMAIL PROTECTED]

Idextrus
E-Business Architects
http://www.idextrus.com
3282 Wilmar Cres.
Mississauga, ON
L5L4B2
CA
905.828.9189


This e-mail and its contents are privileged, confidential and
subject to copyright. If you are not the intended recipient,
please delete this e-mail immediately. Any unauthorized use
or disclosure of the information herein is prohibited.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function to check a valid date

2004-03-20 Thread Ben Ramsey
Your likely to find many ways to do this and many functions with many 
lines of code that do many variations of what you want.  Can I use the 
word "many" many more times?

Such is the way with programming.

Here's my take on it.  Pull all your values into one long string:

$date_string = "{$_POST["week_day"]}, {$_POST["month"]} {$_POST["day"]}, 
{$_POST["year"]}";

Now, you have a string in the format "Saturday, March 20, 2004".

Now, use strtotime() to figure out whether it's a valid date:

if (($timestamp = strtotime($date_string)) === -1) {
// Not a valid date; do some error reporting here
} else {
// It is a valid date, $timestamp is now a valid Unix
// timestamp of $date_string; use it like below:
echo date("m/d/Y", $timestamp);
}
See also http://us4.php.net/strtotime

Chris Bruce wrote:

Hello all,

I was going to build a function to check whether a selected date exists, 
but thought that I would see if anyone has done this type of thing 
already which would indeed save me some time.

I have a form where the users select the day of the week, month, date 
and year from 4 pulldowns. (Saturday, March 20, 2004). I need to have a 
function that will check to see if that is indeed a real date.

Does this sound familiar to anyone?

Thanks a bunch :)

--

Chris Bruce
[EMAIL PROTECTED]
Idextrus
E-Business Architects
http://www.idextrus.com
3282 Wilmar Cres.
Mississauga, ON
L5L4B2
CA
905.828.9189

This e-mail and its contents are privileged, confidential and
subject to copyright.  If you are not the intended recipient,
please delete this e-mail immediately.  Any unauthorized use
or disclosure of the information herein is prohibited.
--
Regards,
 Ben Ramsey
 http://benramsey.com
 http://www.phpcommunity.org/wiki/People/BenRamsey
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: function only available if PHP4 compiled using --enable-exif

2004-02-07 Thread Paul Furman
Thanks. I could have sworn I searched php.ini for exif. I had to do both 
of the below to make it work.

Ben Ramsey wrote:

php.ini 
[extension_dir = "c:\PHP\extensions"]

[uncomment] 
extension=php_exif.dll
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: function only available if PHP4 compiled using --enable-exif

2004-02-07 Thread Ben Ramsey
If you're on Windows, you should see a file by the name of php_exif.dll 
in your PHP\extensions directory.  It should've come with the 
distribution.  Depending on the way your php.ini file is set up, you may 
either leave this file in its current location, or you may need to copy 
it to your windows\system32 folder.  (I have extension_dir in my php.ini 
file set to c:\PHP\extensions\ so I left the file in that directory.)

After checking that, remove the semi-colon (;) from the line before 
extension=php_exif.dll in the list of extensions in the php.ini file. 
Then, restart IIS.

The extension should now work, and you didn't have to recompile anything.

-Ben

Paul Furman wrote:
Does this mean I need to recompile from source code?
(seems an extreme measure to me but what do I know)
Is that difficult to do on a windows machine? I see it in some phpinfo's 
out there like this: http://www.php.net/~jimw/info.php but that's not in 
mine or at school or most hosting companies I'd guess. I'm running 4.3.4

for this function: exif_read_data()
http://us2.php.net/manual/en/function.exif-read-data.php
Note: This function is only available in PHP 4 compiled using 
--enable-exif...

Since PHP 4.3 user comment can automatically change encoding if PHP 4 
was compiled using --enable-mbstring.

This function does not require the GD image library.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Function for crypt and decript.

2004-01-23 Thread Jas
[EMAIL PROTECTED] wrote:
Hi all,
are in PHP, functions for crypt and decrypt string?
I would to use this function in my script in PHP, how can I use this?
I need of an example for use this and a list of this function.
Thanks in advance.

base64_decode() and base64_encode()
http://us2.php.net/manual/en/ref.url.php
crypt()
http://us2.php.net/manual/en/function.crypt.php
mcrypt() - Must have packages installed, but works very well
http://us2.php.net/manual/en/ref.mcrypt.php
openssl() - Also must have packages installed
http://us2.php.net/manual/en/ref.openssl.php
Hope this helps...
Jas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Function Problem (Long-ish)

2004-01-13 Thread David Robley
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 
says...
> Hi List,
> 
> I have a self-made function that uses a MySql statement something like this:
> 
> Function MyFunc(){
>  sql = mysql_query("select * from table where somefield=\"somevar\""){
>   while(blah blah){
>   $var ="blah blah";
>}
>   }
>  return $blah;
> }
> 
> This works ok but if I add a bit to the sql then I get a Warning:
> mysql_fetch_array(): supplied argument is not a valid MySQL result resource
> in error, so if I add:
> 
> Function MyFunc(){
>  sql = mysql_query("select *, count(id) as cnt from table where
> somefield=\"somevar\""){
>   while(blah blah){
>   $var ="blah blah";
>}
>   }
>  return $blah;
> }
> 
> I get the error.
> 
> But this works:
> 
> Function MyFunc(){
>  sql = mysql_query("select count(id) as cnt, sum(numfield) as total from
> table where somefield=\"somevar\""){
>   while(blah blah){
>   $var ="blah blah";
>}
>   }
>  return $blah;
> }
> 
> My Question is Why ?
> 
> Any help is a appreciated and I thank you fully in advance.

Bit hard without seeing your actual code; however if you were to use 
mysql_error() after your call to the database it would probably return you 
a useful error message.

Cheers
-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function returns

2004-01-11 Thread DvDmanDT
Well... Definitly depends on what kind of function it is... However, instead
of echoing in a function, most ppl recommend echo do_it(), were do_it() is
function do_it()
{
return "Hi";
}

There are many builtin functions without a return value, simply cause they
don't need to, or there's no real logic in doing so... If you have a
function named something like output_fmt($str), which is only meant to
format a string and output it, there might not need a return value... Maybe
the output itself, but you get the idea.. Some things just doesn't make
sense to return... And some things might return to a parameter... Right now
I can't think of an example though..
-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
"Shawn McKenzie" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> Maybe a dumb question, but as good coding practice, should all functions
> return something even if they don't need to???
>
> Example:
>
> function do_it()
> {
>echo "hi";
> }
>
> --or--
>
> function do_it()
> {
>return echo "hi";
> }
>
> Also, if they do other things but really don't return anything, should
they
> return true maybe???
>
> Just curious!
> -Shawn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function problems...

2003-12-03 Thread Jas
Nevermind, I got it to work...
cheers
Jas wrote:

I call this function it checks a session variable then displays 1 of 3 
menus... for some reason it will only display the first menu regardless 
of the results of my decoded session var.  Any help or just a new pair 
of eyes would help.  Thanks in advance.
jas

function menu() {
$lvl = base64_decode($_SESSION['lvl']);
echo $lvl;
if (($lvl != "admin") || ($lvl != "user") || ($lvl == "view")) {
$_SESSION['menu'] = "";
} elseif (($lvl != "admin") || ($lvl == "user") || ($lvl != "view")) {
$_SESSION['menu'] = "Manage hosts
 Update DHCP
 ";
} elseif (($lvl == "admin") || ($lvl != "user") || ($lvl != "view")) {
$_SESSION['menu'] = "Global DHCP config.
 Manage VLANS
 Manage hosts
 Update DHCP
 
 Users
  Logs";
} else {
$_SESSION['menu'] = ""; }
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: function that appends dollar symbol

2003-11-23 Thread zerof
Please, see:
http://www.php.net/manual/en/function.localeconv.php

and

http://www.php.net/manual/en/function.setlocale.php

-
zerof
-
"Joffrey Leevy" <[EMAIL PROTECTED]> escreveu na mensagem
news:[EMAIL PROTECTED]
> The money_format function does not do it for me.  Is there a simple php function 
> which
appends the '$'
> symbol to a string value.  Example
--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function disabled.

2003-11-21 Thread Pedro Faria
Hi,

  you have to use *ini_get* function and not *function_exists* because it
is a restriction on PHP.INI.

Try:


[]s
Pedro Faria.

On Fri, 21 Nov 2003 18:58:12 -0500, Vincent M. wrote:

> Hello,
> 
> How to test if a function has been disabled. I tried doing this:
> if(function_exists("rmdir")) {
>echo "rmdir Function exists" ;
> } else {
>echo "rmdir Function DOES NOT exists" ;
> }
> 
> So the test says that the function exists, but if we use  it, I get:
> rmdir() has been disabled for security reasons
> 
> How to test if the function has been disabled ?
> 
> Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: function help redirect help

2003-10-27 Thread Chris Shiflett
--- DvDmanDT <[EMAIL PROTECTED]> wrote:
> > Can you see the problem(s) now? Never underestimate the benefits of
> > writing clean code. :-)
> 
> Hehe, you should see my code..

Yes, very messy and disorganized. Is this an admission of guilt, a cry for
help, or what?

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: function help simple redirect

2003-10-27 Thread Frank Tudor
Shit!

payment();  WORKS!

Thank for teach me how to do a function guys!!!

Frank


--- Frank Tudor <[EMAIL PROTECTED]> wrote:
> Oh?!?!
> 
> Sweet!  thanks...  let me try that and get back to the group
> 
> :)
> 
> 
> --- Pablo Gosse <[EMAIL PROTECTED]> wrote:
> > On Monday, October 27, 2003 11:26 AM, Frank Tudor wrote:
> > 
> > > This one worked (kinda)
> > > I have no more errors but it doesn't do the redirect
> > (hmmm)??
> > >  > > $payment = "1";
> > > 
> > > function payment(){
> > > global $payment;
> > > if ($payment == "0"){
> > > header ('Location: http://ftudor/test/test_page.html');
> > > 
> > > }
> > > elseif ($payment == "1") {
> > > header ('Location: http://ftudor/test/test_page2.html');
> > > 
> > > }
> > > }
> > > ?>
> > 
> > You need to add payment(); to your php code.
> > 
> > The function is defined, but it's not going to do anything
> > until you
> > call it.
> > 
> > Cheers,
> > Pablo
> 
> 
> __
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: function help simple redirect

2003-10-27 Thread Frank Tudor
Oh?!?!

Sweet!  thanks...  let me try that and get back to the group

:)


--- Pablo Gosse <[EMAIL PROTECTED]> wrote:
> On Monday, October 27, 2003 11:26 AM, Frank Tudor wrote:
> 
> > This one worked (kinda)
> > I have no more errors but it doesn't do the redirect
> (hmmm)??
> >  > $payment = "1";
> > 
> > function payment(){
> > global $payment;
> > if ($payment == "0"){
> > header ('Location: http://ftudor/test/test_page.html');
> > 
> > }
> > elseif ($payment == "1") {
> > header ('Location: http://ftudor/test/test_page2.html');
> > 
> > }
> > }
> > ?>
> 
> You need to add payment(); to your php code.
> 
> The function is defined, but it's not going to do anything
> until you
> call it.
> 
> Cheers,
> Pablo


__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: function help simple redirect

2003-10-27 Thread Frank Tudor
I get my ugly purple test page

:)

Frank

--- Chris Shiflett <[EMAIL PROTECTED]> wrote:
> --- Frank Tudor <[EMAIL PROTECTED]> wrote:
> > I am putting in the $payment="1"; so it will automatically
> go to
> > test_page2.html but it just sits there.
> [snip]
> > header ('Location: http://ftudor/test/test_page2.html');
> 
> What happens when you type it into your browser manually?
> 
> http://ftudor/test/test_page2.html
> 
> That might be your problem now.
> 
> Chris
> 
> =
> My Blog
>  http://shiflett.org/
> HTTP Developer's Handbook
>  http://httphandbook.org/
> RAMP Training Courses
>  http://www.nyphp.org/ramp


__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: function help redirect help

2003-10-27 Thread DvDmanDT
> Can you see the problem(s) now? Never underestimate the benefits of
writing
> clean code. :-)

Hehe, you should see my code..

function dp_neg($v1,$v2){
$neg = ((substr((string)$v1,0,1)=="-")||((substr((string)$v2,0,1)=="-")));
$bneg= ((substr((string)$v1,0,1)=="-")&&((substr((string)$v2,0,1)=="-")));
if(!$bneg && $neg){
$tmp=$v1*$v2;
$tmp=(string)$tmp;
$an=str_replace("-","+",$tmp);
}
else{
$an="-".($v1*$v2);
}
return $an;
}
function xyz($f,$s){
$f=s_str($f);
$s=s_str($s);
$t=($f==$s)?$f:s_str($f.$s);
return $t;
}
function s_str($str)
{$l=strlen($str);for($x=0;$x<$l;$x++){$ar[]=$str{$x};}sort($ar);return
implode('',$ar);}
$e_a[0]=gs($e1);$e_a[1]=gs($e2);
$e_a[2]=gs($e3);$e_a[3]=gs($e4);
for($i=0;$i<4;$i++){
$t[$i]=split(":",$e_a[$i]);}
$r[0][0]=dp_neg($t[0][3],$t[2][3]);
$r[0][1]=xyz($t[0][2],$t[2][2]);
$r[1][0]=dp_neg($t[0][3],$t[3][3]);
$r[1][1]=xyz($t[0][2],$t[3][2]);
$r[2][0]=dp_neg($t[1][3],$t[2][3]);
$r[2][1]=xyz($t[1][2],$t[2][2]);
$r[3][0]=dp_neg($t[1][3],$t[3][3]);
$r[3][1]=xyz($t[1][2],$t[3][2]);
for($i=0;$i<4;$i++){
$exp .=
((substr($r[$i][0],0,1)=="-")?$r[$i][0].$r[$i][1]:($r[$i][0].$r[$i][1]))."
";}


No, that probably wont compile as that's only a little part of it, but still
a pretty easy part of it.. :)
-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
##
Please, if you are using windows, you may be infected by Swen. Please go
here to find out more:
http://us.mcafee.com/virusInfo/default.asp?id=helpCenter&hcName=swen
http://securityresponse.symantec.com/avcenter/venc/data/[EMAIL PROTECTED]
##

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: function help simple redirect

2003-10-27 Thread Pablo Gosse
On Monday, October 27, 2003 11:26 AM, Frank Tudor wrote:

> This one worked (kinda)
> I have no more errors but it doesn't do the redirect (hmmm)??
>  $payment = "1";
> 
> function payment(){
> global $payment;
> if ($payment == "0"){
> header ('Location: http://ftudor/test/test_page.html');
> 
> }
> elseif ($payment == "1") {
> header ('Location: http://ftudor/test/test_page2.html');
> 
> }
> }
> ?>

You need to add payment(); to your php code.

The function is defined, but it's not going to do anything until you
call it.

Cheers,
Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: function help simple redirect

2003-10-27 Thread Chris Shiflett
--- Frank Tudor <[EMAIL PROTECTED]> wrote:
> I am putting in the $payment="1"; so it will automatically go to
> test_page2.html but it just sits there.
[snip]
> header ('Location: http://ftudor/test/test_page2.html');

What happens when you type it into your browser manually?

http://ftudor/test/test_page2.html

That might be your problem now.

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: function help simple redirect

2003-10-27 Thread Frank Tudor
This one worked (kinda)

I have no more errors but it doesn't do the redirect (hmmm)??

So now here is what it looks like: 

I am putting in the $payment="1"; so it will automatically go to
test_page2.html but it just sits there.

Is there a headers thing already going on blocking this?

I know don't need the quotes around the "1" because it's a
number vaule and not a string.

Can anyone think of any other reason why it might not work?

Frank

http://ftudor/test/test_page.html');

}
elseif ($payment == "1") {
header ('Location: http://ftudor/test/test_page2.html');

}
}
?>

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: function help redirect help

2003-10-27 Thread Chris Shiflett
--- Frank Tudor <[EMAIL PROTECTED]> wrote:
> function payment()
> {
>  global $payment;
>  if ($payment == '0'); 
>  header ('Location: http://ftudor/test/test_page.html');
> }
> 
> elseif ($payment == '1')
> {
>  header ('Location: http://ftudor/test/test_page2.html');
> }

Your code looks cleaner, so now isn't the error very obvious?

It seems to me that you intended your first conditional statement to send the
Location header when true. Therefore, you did not mean to put a semicolon there
but rather a curly brace.

This is why your function ends prematurely (assuming you did not intend for it
to end there), and then you have an elseif statement dangling around with no
corresponding if.

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: function help redirect help

2003-10-27 Thread Frank Tudor
I made the changes but I am getting:

Parse error: parse error, unexpected T_ELSEIF

I did take the second global statement out after I cut and
pasted your code and modified the urls

so now here is what it looks like (the whole thing).

Frank


http://ftudor/test/test_page.html');
}

elseif ($payment == '1')
{
 header ('Location: http://ftudor/test/test_page2.html');
}



?>

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function help simple redirect

2003-10-27 Thread DvDmanDT
$payment = "1";

function payment(){
global $payment;
if ($payment == "0"){
header ("Location: test_page.html");
}
elseif ($payment == "1") {
header ("Location: test_page2.html");
}
}
-- 
// DvDmanDT
MSN: dvdmandt¤hotmail.com
Mail: dvdmandt¤telia.com
##
Please, if you are using windows, you may be infected by Swen. Please go
here to find out more:
http://us.mcafee.com/virusInfo/default.asp?id=helpCenter&hcName=swen
http://securityresponse.symantec.com/avcenter/venc/data/[EMAIL PROTECTED]
##
"Frank Tudor" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> Sorry I'm getting this error message
>
> Parse error: parse error, unexpected T_ELSEIF
>
> __
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: function help redirect help

2003-10-27 Thread Chris Shiflett
--- Frank Tudor <[EMAIL PROTECTED]> wrote:
> I am getting a elseif parse error.

Let me clean up your code a bit, and hopefully the error will stand out.

function payment()
{
 global $payment;
 if ($payment == '0'); 
 header ('Location: http://example.org/test_page.html');
}

global $payment;

elseif ($payment == '1')
{
 header ('Location: http://example.org/test_page2.html');
}

Can you see the problem(s) now? Never underestimate the benefits of writing
clean code. :-)

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: function help simple redirect

2003-10-27 Thread Frank Tudor
Sorry I'm getting this error message

Parse error: parse error, unexpected T_ELSEIF

__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] RE: function help redirect help

2003-10-27 Thread Gregory Kornblum
Remove the second 'global $payment;'. Regards.

-Gregory

-Original Message-
From: Frank Tudor [mailto:[EMAIL PROTECTED]
Sent: Monday, October 27, 2003 2:01 PM
To: 1PHP
Subject: [PHP] RE: function help redirect help


Here is what Ihave

I am getting a elseif parse error.  Is there something I'm
leaving out?

Frank

code
---

$payment = "1";

function payment(){
global $payment;
if ($payment == "0"); 
header ("location:test_page.html");
}
global $payment;
elseif ($payment == "1") {
header ("location:test_page2.html");
}

__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: function help redirect help

2003-10-27 Thread Frank Tudor
Here is what Ihave

I am getting a elseif parse error.  Is there something I'm
leaving out?

Frank

code
---

$payment = "1";

function payment(){
global $payment;
if ($payment == "0"); 
header ("location:test_page.html");
}
global $payment;
elseif ($payment == "1") {
header ("location:test_page2.html");
}

__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: function help redirect help

2003-10-27 Thread Frank Tudor
$payment = "1";

function payment(){
global $payment;
if ($payment == "0"); 
header ("location:test_page.html");
}
global $payment;
elseif ($payment == "1") {
header ("location:test_page2.html");
}

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Function/globalizing

2003-03-16 Thread Joel Colombo
Try:

somewhere global define :
   $encryptiontechnique = 'ENCRYPT ALGORITHM';


function encryptPassword($password, $salt='') {
global $encryptiontechnique; if ($salt === '') { $salt =
$encryptiontechnique; }
// CODE..

}

Joel Colombo





"Liam Gibbs" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
I have a function, such as this:

function encryptPassword($password, $salt = $encryptiontechnique) {
}

$encryptiontechnique is defined, obviously outside the function. How is it
possible to make $encryptiontechnique global so that this will work?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function getting redeclared

2003-02-18 Thread Greg Beaver
Hi Erik,

You may want to re-investigate using nested functions for this purpose, it
seems a bit illogical.  The main reason is that it clutters up the source.
If you want a private function, use docblock tag @access private to let
other users know that it should not be accessed directly, or wait for php 5
when you can declare a method to be private/protected.

Having said that, if you are still into nested functions, try using

if (!method_exists($this,'isValidPhoneNumber'))
{
..
}

Greg

"Erik Price" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> I have a problem where I am getting the following error, and I was
> wondering if anyone has seen this one before and can help me out.
>
> "Fatal error:  Cannot redeclare isvalidphonenumber() (previously
> declared in /home/bluekomo/public_html//classes/Registrant.class:360)
> in /home/bluekomo/public_html//classes/Registrant.class on line 360"
>
> I have a script, "registration.php", which calls require_once on the
> Registrant.class file mentioned in the above error message.  The
> Registrant::setPhone() method is called more than once.  Since it is
> called more than once, the function "isValidPhoneNumber()" defined
> within setPhone() is defined more than once, which I suspect is the
> source of the problem.  Does PHP not allow you to define a function
> within a function and then call the enclosing function more than once?
> Here is the relevant section of code:
>
> 354 /**
> 355  * sets the phone property
> 356  */
> 357 function setPhone($phone) {
> 358 // TODO: determine if these formats are acceptable
> 359 // TODO: account for extensions (separate form field?)
> 360 function isValidPhoneNumber($num) {
> 361 $valid = false;
> 362 if (preg_match('!\d{9,9}!', $num)) {
> 363 $valid = true;
> 364 }
> 365 if (preg_match('!\(?\d\d\d\)?-?\s*\d\d\d-?\s*\d\d\d\d!',
> 366 $num)) {
> 367
> 368 $valid = true;
> 369 }
> 370
> 371 return $valid;
> 372 }
> 373
> 374 if (isValidPhoneNumber($phone)) {
> 375 $this->phone = $phone;
> 376 }
> 377 }
>
>
> I am using PHP 4.3.0 on a RedHat machine with Apache 1.3.x.
>
> Thanks for your help, it's been a while since I've used PHP!
>
>
> Erik
>
>
>
>
>
>
>
> --
> Erik Price
>
> email: [EMAIL PROTECTED]
> jabber: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function returning a reference - how ?!?

2002-12-21 Thread Kyle Gibson
I'll try.


/* This function instantiates and returns a new Parent class. */
function createParent()
{
return new Parent;
}
/* $p is a reference of the Parent object created by createParent(). */
$p = &createParent();


I believe the problem occurs here. $p becomes a reference to the 
createParent() function whose return value is the Parent object.

This *should* work:

function createParent()
{
	//the lack of the '()' might have caused other problems
	return &new Parent();
}

$p = createParent();

That way $p equals the value that is returned by the function 
createParent, which is a reference to the Parent object.

Then again, I haven't tested any of this, just going on some instinct here.

--
Kyle Gibson
admin(at)frozenonline.com
http://www.frozenonline.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: function/class for updating multiple-tables automatically?

2002-12-16 Thread Thomas Seifert
oh, some addendum, I would need it for MySQL if its dependend.


Thomas

On Mon, 16 Dec 2002 21:46:34 +0100 [EMAIL PROTECTED] (Thomas Seifert) wrote:

> Hi folks,
> 
> I'm looking for a function or class which is able to automatically update
> multiple tables.
> 
> The hard thing on this is, I only want to give it some predefined arrays which
> define the table-structures (and maybe aliases for some fields) and on execution 
> it only gets some field-names and their corresponding values.
> It should compute then the required tables to update based on the involved fields
> and update them with the values given.
> 
> I know I could do it on my own with some work but I'm hoping someone has already 
> developed something like that.
> 
> 
> Thanks,
> 
> Thomas

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: function args declared by-reference, with default value?

2002-11-25 Thread Derick Rethans
Nick Eby wrote:

true or false:

when declaring a function, a given argument can be declared to pass by
reference, or can be declared to have a default value, but never both.

i.e., you can only write one of:
function foo(&$param)
function foo($param = "bar")

but never the equivalent of:
function foo(&$param = "bar")

is there a way to declare an argument with both pass-by-reference and
default-value properties?


No, but this will be supported by Zend Engine 2, which will drive PHP 5 and 
higher.

--

-
 Derick Rethans http://derickrethans.nl/
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Function Problem

2002-11-10 Thread Ernest E Vogelsinger
At 08:16 10.11.2002, conbud said:
[snip]
>also I have the function wrong in my original question I have it as
>function db_conn($host,$user,$pass,$dab)
>{
>$db = mysql_connect("$host", "$user","$pass"
>mysql_select_db("$dab",$db);
>}
>
>and not
>function db_conn($host,$user,$pass,$dab)
>{
>$db = mysql_connect("$host", "$user","$pass")mysql_select_db("$dab",$db);
>}
[snip] 

mysql_select_db already opens a connection to the database; you don't need
the mysql_connect() call afterwards.

In your code you have mysql_select_db() as fourth parameter to
mysql_connect(). While the fourth parameter is boolean and won't generate
any error at runtime, it's use- and senseless. The 4th parameter on
mysql_connect specifies if PHP should use an existing link, or create a new
one.

You should decide whether you want to go with mysql_select_db() or
mysql_connect().


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Function Problem

2002-11-09 Thread conbud
huh I thought I tried that befoer and it didnt work but this time it worked
good, thanks everyone.

Also whats the difference between $globals['$variable'] and just global

-Lee

"Maxim Maletsky" <[EMAIL PROTECTED]> wrote in message
news:20021110082455.7C29.MAXIM@;php.net...
>
> you need to return $db:
>
> function db_conn($host,$user,$pass,$dab)
> {
> $db = mysql_connect("$host", "$user","$pass"
> mysql_select_db("$dab",$db);
> return $db;
> }
>
> and then use $db = db_conn(,,,);
>
> or make it global:
>
>
> function db_conn($host,$user,$pass,$dab)
> {
> blobal $db;
> $db = mysql_connect("$host", "$user","$pass"
> mysql_select_db("$dab",$db);
> }
>
> --
> Maxim Maletsky
> [EMAIL PROTECTED]
>
>
> On Sun, 10 Nov 2002 02:16:14 -0500 "conbud" <[EMAIL PROTECTED]> wrote:
>
> > also I have the function wrong in my original question I have it as
> > function db_conn($host,$user,$pass,$dab)
> > {
> > $db = mysql_connect("$host", "$user","$pass"
> > mysql_select_db("$dab",$db);
> > }
> >
> > and not
> > function db_conn($host,$user,$pass,$dab)
> > {
> > $db = mysql_connect("$host",
"$user","$pass")mysql_select_db("$dab",$db);
> > }
> >
> >
> > "Conbud" <[EMAIL PROTECTED]> wrote in message
> > news:20021110065837.99825.qmail@;pb1.pair.com...
> > > Hey
> > > Im trying to create a fucntion in an include file
> > > function db_conn($host,$user,$pass,$dab)
> > > {
> > > $db = mysql_connect("$host",
"$user","$pass")mysql_select_db("$dab",$db);
> > > }
> > > 
> > > 
> > > In the page ide use:
> > > require('func.inc.php');
> > > db_conn("$host","$user","$pass","$dab");
> > > $result = mysql_query("select * FROM $page",$db);
> > > $myrow = mysql_fetch_array($result);
> > >
> > > echo $myrow['general_info'];
> > >
> > > ...
> > > ...
> > > however when I use the db_conn on the webpage I just get a mysql error
> > > saying not a valid resource, so how do I get the db_conn to actually
> > return
> > > the data, ive tried using
> > >
> > > function db_conn($host,$user,$pass,$db)
> > > {
> > > $db = mysql_connect("$host",
"$user","$pass")mysql_select_db("$db",$db);
> > >
> > > return $db
> > > }
> > >
> > > and various other thing but still nothing, I have to actually put the
echo
> > > statements in the function too to get it to work properlly, any ideas?
> > >
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Function Problem

2002-11-09 Thread Maxim Maletsky

you need to return $db:

function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect("$host", "$user","$pass"
mysql_select_db("$dab",$db);
return $db;
}

and then use $db = db_conn(,,,);

or make it global:


function db_conn($host,$user,$pass,$dab)
{
blobal $db;
$db = mysql_connect("$host", "$user","$pass"
mysql_select_db("$dab",$db);
}

-- 
Maxim Maletsky
[EMAIL PROTECTED]


On Sun, 10 Nov 2002 02:16:14 -0500 "conbud" <[EMAIL PROTECTED]> wrote:

> also I have the function wrong in my original question I have it as
> function db_conn($host,$user,$pass,$dab)
> {
> $db = mysql_connect("$host", "$user","$pass"
> mysql_select_db("$dab",$db);
> }
> 
> and not
> function db_conn($host,$user,$pass,$dab)
> {
> $db = mysql_connect("$host", "$user","$pass")mysql_select_db("$dab",$db);
> }
> 
> 
> "Conbud" <[EMAIL PROTECTED]> wrote in message
> news:20021110065837.99825.qmail@;pb1.pair.com...
> > Hey
> > Im trying to create a fucntion in an include file
> > function db_conn($host,$user,$pass,$dab)
> > {
> > $db = mysql_connect("$host", "$user","$pass")mysql_select_db("$dab",$db);
> > }
> > 
> > 
> > In the page ide use:
> > require('func.inc.php');
> > db_conn("$host","$user","$pass","$dab");
> > $result = mysql_query("select * FROM $page",$db);
> > $myrow = mysql_fetch_array($result);
> >
> > echo $myrow['general_info'];
> >
> > ...
> > ...
> > however when I use the db_conn on the webpage I just get a mysql error
> > saying not a valid resource, so how do I get the db_conn to actually
> return
> > the data, ive tried using
> >
> > function db_conn($host,$user,$pass,$db)
> > {
> > $db = mysql_connect("$host", "$user","$pass")mysql_select_db("$db",$db);
> >
> > return $db
> > }
> >
> > and various other thing but still nothing, I have to actually put the echo
> > statements in the function too to get it to work properlly, any ideas?
> >
> >
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function Problem

2002-11-09 Thread conbud
also I have the function wrong in my original question I have it as
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect("$host", "$user","$pass"
mysql_select_db("$dab",$db);
}

and not
function db_conn($host,$user,$pass,$dab)
{
$db = mysql_connect("$host", "$user","$pass")mysql_select_db("$dab",$db);
}


"Conbud" <[EMAIL PROTECTED]> wrote in message
news:20021110065837.99825.qmail@;pb1.pair.com...
> Hey
> Im trying to create a fucntion in an include file
> function db_conn($host,$user,$pass,$dab)
> {
> $db = mysql_connect("$host", "$user","$pass")mysql_select_db("$dab",$db);
> }
> 
> 
> In the page ide use:
> require('func.inc.php');
> db_conn("$host","$user","$pass","$dab");
> $result = mysql_query("select * FROM $page",$db);
> $myrow = mysql_fetch_array($result);
>
> echo $myrow['general_info'];
>
> ...
> ...
> however when I use the db_conn on the webpage I just get a mysql error
> saying not a valid resource, so how do I get the db_conn to actually
return
> the data, ive tried using
>
> function db_conn($host,$user,$pass,$db)
> {
> $db = mysql_connect("$host", "$user","$pass")mysql_select_db("$db",$db);
>
> return $db
> }
>
> and various other thing but still nothing, I have to actually put the echo
> statements in the function too to get it to work properlly, any ideas?
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: function()

2002-11-05 Thread Joshua E Minnie
First of all, you can't echo that variable in the manner you are trying.

Try this instead:

[lib.inc]
function test_func($param1) {
  return $param1;
}


[main.php]


HTH


  _
 / Joshua Minnie\
++---+
| Wild Web Technology|
| Independent Web Consultant/Developer   |
| [EMAIL PROTECTED]   |
||
| Tel : 616.890.1566 |
++


"Francisco Vaucher" <[EMAIL PROTECTED]> wrote:
| Hi to all,
|
| I have a problem with function() and some variables.
|
| The issue is this
|
| I declare the function, suppose:
|
| function test_func($param1) {
| echo $param1;
| }
|
| when I call the function like;
|
| 
|
| works OK!
|
| But if I try something like this:
|
| 
|
| This doesn't work. I need to get some variables values out of the
function.
| Is there a way to make te variables defined in the function 'global' ? So
I
| can use them after the function call.
|
| Thanks in advance!!
|
| regards,
|
| f.
|



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function: return multple values

2002-09-23 Thread Ivo

You can only as an array:
function calculate_money($sum)
{
// some hanky panky calculations
$myArr[] = $type;
$myArr[] = $amount;
return $myArr;
}

or shorter:
function calculate_money($sum) { return array($type, $amount); }

"Faisal Abdullah" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi people.
> Is it possible to return multiple values in a function.
> For instance, i want to do something like this:
>
> function calculate_money($sum)
>  {
>  // some hanky panky calculations
> return $type;
> return $amount;
>  }
>
> Thanks!
>
> Sincerely,
> Faisal
>
> __
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: Function search utility

2002-08-02 Thread Brian V Bonini

Nope, it was this http://www.php.net/tips.php that I was thiking of
But thanks, I didn't know you could do that ;-)

-Brian

> -Original Message-
> From: Lars Olsson [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 02, 2002 2:41 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Re: Function search utility
> 
> 
> It still works...try http://www.php.net/mysql or 
> http://www.php.net/fopen for example...
> 
> /lasso ([EMAIL PROTECTED])
> 
> 
> 
> Brian V Bonini wrote:
> > There used to be a utility that let you search php functions from the
> > address bar in your browser by simply appening PHP to the 
> function name eg,
> > php mail I thikn it might of been an IE only thing...
> > 
> > I can't remember were I originally got it form and can not find 
> it again,
> > does anyone know?
> > 
> > -Brian
> > 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function search utility

2002-08-02 Thread Lars Olsson

It still works...try http://www.php.net/mysql or 
http://www.php.net/fopen for example...

/lasso ([EMAIL PROTECTED])



Brian V Bonini wrote:
> There used to be a utility that let you search php functions from the
> address bar in your browser by simply appening PHP to the function name eg,
> php mail I thikn it might of been an IE only thing...
> 
> I can't remember were I originally got it form and can not find it again,
> does anyone know?
> 
> -Brian
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: function for finding one character in a string?

2002-07-18 Thread Richard Lynch

>I have been looking around in the PHP function listing for a function that
>can find or match one character from a string.  I thought it would be
>something like post_str() or something but never found anything close to
>that.  I get the idea of post and str from the SQL command.  I did check the
>ereg() but it is so confusing, no clear instruction on it.
>
>--clip--
> $str = "";
> $str = "X";
> $str = "XY"
> $str = "Y";
> $str = "YX";
>--clip--
>
>Those same variables from above, I only need to know if hte "X" exist in the
>string, nothing else.

http://php.net/strstr


-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Function needed

2002-06-09 Thread Gaylen Fraley

This resricts to *nix and can be disallowed due to security constraints, but
thanks anyway.  I just wrote my own PHP routine.

--
Gaylen
PHP KISGB v4.0.5 Guest Book http://www.gaylenandmargie.com/phpwebsite/

"Chris Hewitt" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> $result=`ls -R | grep 'expression' ./`;
>
> HTH
> Chris
>
> Jason Wong wrote:
>
> >On Sunday 09 June 2002 17:17, Austin Marshall wrote:
> >
> >>Gaylen Fraley wrote:
> >>
> >>>I am in need of a function/script that will take a directory and search
> >>>all filenames, recursively down, for a given file.  Can anyone point me
> >>>to a source?  Thanks.
> >>>
> >>$result=`grep -r 'expression' ./`;
> >>
> >
> >This searches for strings within a file.
> >
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Function needed

2002-06-09 Thread Chris Hewitt

$result=`ls -R | grep 'expression' ./`;

HTH
Chris

Jason Wong wrote:

>On Sunday 09 June 2002 17:17, Austin Marshall wrote:
>
>>Gaylen Fraley wrote:
>>
>>>I am in need of a function/script that will take a directory and search
>>>all filenames, recursively down, for a given file.  Can anyone point me
>>>to a source?  Thanks.
>>>
>>$result=`grep -r 'expression' ./`;
>>
>
>This searches for strings within a file.
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Function needed

2002-06-09 Thread Jason Wong

On Sunday 09 June 2002 17:17, Austin Marshall wrote:
> Gaylen Fraley wrote:
> > I am in need of a function/script that will take a directory and search
> > all filenames, recursively down, for a given file.  Can anyone point me
> > to a source?  Thanks.
>
> $result=`grep -r 'expression' ./`;

This searches for strings within a file.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Earth -- mother of the most beautiful women in the universe.
-- Apollo, "Who Mourns for Adonais?" stardate 3468.1
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function needed

2002-06-09 Thread Austin Marshall

Gaylen Fraley wrote:
> I am in need of a function/script that will take a directory and search all
> filenames, recursively down, for a given file.  Can anyone point me to a
> source?  Thanks.
> 
> 
> 

$result=`grep -r 'expression' ./`;


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Function Switch($pid) - NEED HELP

2002-05-25 Thread Jens Lehmann

> I have a script that switches.
> switch($pid)
> {
> case 1:
> break;
>
> case 2:
> break;
> }
>
> Now I'm doing a check in case 1 and if everything goes well, i want to
> switch directly to case 2 while the script is runny.
>
> How would i do that ???
>

Please don't post the same question several times.

Jens



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: function over loading?

2002-05-12 Thread Miguel Cruz

On Sun, 12 May 2002, Smileyq wrote:
> [EMAIL PROTECTED] (Kris Vose) wrote:
>> Can you practice function over-loading in php?
>
> No you cannot overload in PHP.

In a particularly masochistic project, we achieved function overloading by 
creating a global array $F that linked public to hidden names of all our 
functions. To overload, just change the hidden name.

  $F['list_items'] = 'main_list_items';

Then later, if we wanted to overload list_items, just do

  $F['list_items'] = 'substitute_list_items';

This functions would be called like:

  $F['list_items']($param1, $param2, $etc);

It worked fine but sure took some getting used to.

miguel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: function over loading?

2002-05-12 Thread Rasmus Lerdorf

Well, not in the procedural sense, but you can do method and property
overloading on objects.  See http://php.net/overload

-Rasmus

On Sun, 12 May 2002, Smileyq wrote:

> In article
> <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Kris Vose) wrote:
>
> > Can you practice function over-loading in php?
> >
> > Kris
>
> No you cannot overload in PHP.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: function over loading?

2002-05-12 Thread Jason Murray

> > Can you practice function over-loading in php?
> 
> No you cannot overload in PHP.

You can achieve the same effect (having the same function do
something else in a different circumstance) by making
parameters optional:



$param1 is required, $param2 is optional - if its not
supplied when the function is called, it will be "".

J

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: function over loading?

2002-05-12 Thread Smileyq

In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Kris Vose) wrote:

> Can you practice function over-loading in php?
>  
> Kris

No you cannot overload in PHP.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: function over loading?

2002-05-06 Thread J Smith


Sort of. Look at the extension "overload" in the ext directory of the PHP 
source. Enable it and check out the docs:

http://www.php.net/manual/en/ref.overload.php

J



Kris Vose wrote:

> Can you practice function over-loading in php?
>  
> Kris


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




  1   2   >