[PHP] Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
I got different portions of code only used for certain purposes (who don't 
;-)?). But what, in your opinion (better: in your experience) would be the 
best regarding script-performance: Putting each code-portion in a separate 
file and include it if required, putting it in a constant-dependent 
if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) 
or simply let it be parsed every time?

My first choice is using separate files, but if a file e.g. only contains 20 
lines, I fear it would take much longer to include the file against simply 
parsing these lines in the existing file. And as parsing is done really 
fast, there might be no real performance-loss in case of not using the 
mentioned code. With the constant-dependent if-structure I don't know if 
there are any performance-benefits if FOO isn't defined or defined as FALSE.

Looks for me a bit like a philosophical question, but maybe you have 
something to say about it nevertheless. A good thing for me would be 
something like: up to 125 lines of code you get an adequate performance with 
simply parsing it every time, with more than 125 lines you would get a 
better performance with using separate files - just kidding, surely the 
number of lines in this case is 42 ;-).

Looking forward to your answers
Thomas 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 08:56 +0100, [EMAIL PROTECTED] wrote:
> I got different portions of code only used for certain purposes (who don't 
> ;-)?). But what, in your opinion (better: in your experience) would be the 
> best regarding script-performance: Putting each code-portion in a separate 
> file and include it if required, putting it in a constant-dependent 
> if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) 
> or simply let it be parsed every time?
> 
> My first choice is using separate files, but if a file e.g. only contains 20 
> lines, I fear it would take much longer to include the file against simply 
> parsing these lines in the existing file. And as parsing is done really 
> fast, there might be no real performance-loss in case of not using the 
> mentioned code. With the constant-dependent if-structure I don't know if 
> there are any performance-benefits if FOO isn't defined or defined as FALSE.
> 
> Looks for me a bit like a philosophical question, but maybe you have 
> something to say about it nevertheless. A good thing for me would be 
> something like: up to 125 lines of code you get an adequate performance with 
> simply parsing it every time, with more than 125 lines you would get a 
> better performance with using separate files - just kidding, surely the 
> number of lines in this case is 42 ;-).

Install a compile cache like eaccelerator or APC. keep your code
organized, that usually means use multiple files for the code.

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] Structured Code vs. Performance

2007-11-29 Thread Tomi Kaistila
> I got different portions of code only used for certain purposes (who
> don't
> ;-)?). But what, in your opinion (better: in your experience) would be
> the
> best regarding script-performance: Putting each code-portion in a
> separate
> file and include it if required, putting it in a constant-dependent
> if-structure (if (defined('FOO') && FOO) {class foo{}; function foo();
> ...})
> or simply let it be parsed every time?
> 
> My first choice is using separate files, but if a file e.g. only
> contains 20
> lines, I fear it would take much longer to include the file against
> simply
> parsing these lines in the existing file. And as parsing is done really
> fast, there might be no real performance-loss in case of not using the
> mentioned code. With the constant-dependent if-structure I don't know
> if
> there are any performance-benefits if FOO isn't defined or defined as
> FALSE.
> 
> Looks for me a bit like a philosophical question, but maybe you have
> something to say about it nevertheless. A good thing for me would be
> something like: up to 125 lines of code you get an adequate performance
> with
> simply parsing it every time, with more than 125 lines you would get a
> better performance with using separate files - just kidding, surely the
> number of lines in this case is 42 ;-).
> 
> Looking forward to your answers
> Thomas

To my understanding (and anyone who thinks differently can correct me) there
is very little performance loss in including (or requiring) multiple files,
unless the number of files reaches something like over a hundred. This says
nothing about the amount of code in those file of course. But like you said,
parsing is fast.

I personally prefer the approuch:

1 directory = package
1 subdirectory = subpackage
1 .php file = class

I haven't noticed that much performance degradation in my scripts, while
have amounts several dozen of files.

You can avoid duplication by only using require_once or include_once. PHP
automatically does the checking that the file is not included if it has
already been included once. The Zend framework works this way for instance.
Just simply require_once, at the beginning of the file, everything the file
in question needs.

Constants on the global scope are a bit of a different case. But if you do a
lot of objects, you can instead of the global scope put all of your
constants into classes, which works just as well. This avoids name
conflicts.

Hope that answered your question.


Tomi Kaistila
PHP Developer

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Chris

[EMAIL PROTECTED] wrote:
I got different portions of code only used for certain purposes (who don't 
;-)?). But what, in your opinion (better: in your experience) would be the 
best regarding script-performance: Putting each code-portion in a separate 
file and include it if required, putting it in a constant-dependent 
if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) 
or simply let it be parsed every time?


Make your code readable and manageable first, then worry about the rest. 
I always go for multiple files because it means the project is much more 
manageable.


My first choice is using separate files, but if a file e.g. only contains 20 
lines, I fear it would take much longer to include the file against simply 
parsing these lines in the existing file.


Put your "misc" functions in one file and include it when you need it.

--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
> I got different portions of code only used for certain purposes (who don't 
> ;-)?). But what, in your opinion (better: in your experience) would be the 
> best regarding script-performance: Putting each code-portion in a separate 
> file and include it if required, putting it in a constant-dependent 
> if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended, because it
means they can only be defined at runtime and not compile time ... which will
kill any op-code caching you might have in place or use in future (e.g. 
php.net/apc)

> or simply let it be parsed every time?
> 
> My first choice is using separate files, but if a file e.g. only contains 20 
> lines, I fear it would take much longer to include the file against simply 
> parsing these lines in the existing file. And as parsing is done really 
> fast, there might be no real performance-loss in case of not using the 
> mentioned code. With the constant-dependent if-structure I don't know if 
> there are any performance-benefits if FOO isn't defined or defined as FALSE.
> 
> Looks for me a bit like a philosophical question, but maybe you have 
> something to say about it nevertheless. A good thing for me would be 
> something like: up to 125 lines of code you get an adequate performance with 
> simply parsing it every time, with more than 125 lines you would get a 
> better performance with using separate files - just kidding, surely the 
> number of lines in this case is 42 ;-).

for a few 1000 lines of code the difference is probably not measurable in any
meaningful way (a spam assassin deamon, or something similar, hogging the CPU
will probably have more realworld effect on the speed of your script).

when your app becomes very large you will probably benefit from only including
little used code when it is actually required.

there is also the issue of maintainability - having to check and keep track of
include/require statements scattered all through the code, and working through
'undefined class/function' errors when enhancing/bugfixing/refactoring code 
maybe
alot more hassle than using a single global 'init' script that includes pretty 
much
everything bit of code your scripts might need.

personally I tend to go for maintainability over performance if the choice is
mutually exclusive - generally your time is alot more costly than the purchase
and placement of extra RAM, faster CPU, faster disks, etc.

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Tomi Kaistila wrote:

...

> 
> You can avoid duplication by only using require_once or include_once. PHP

indeed require_once() and include_once() help with maintainability but it
should be mentioned that if you are going to use an op-code cache (as Rob
Cummings mentioned also) then it is highly recommended that you stick to
using require() and include() as, IIRC, op-code caches handle your includes
much faster when they are 'unconditional' (probably not the correct word in this
context but what I mean is that there is no check to see if the file has been
previously included)

also using an absolute path in your include statements helps php (and the
op-code cache if you use it) it go a little faster because there is no need
to work through the directories defined in the include_path ini setting to
find the file.

> automatically does the checking that the file is not included if it has
> already been included once. The Zend framework works this way for instance.
> Just simply require_once, at the beginning of the file, everything the file
> in question needs.
> 
> Constants on the global scope are a bit of a different case. But if you do a
> lot of objects, you can instead of the global scope put all of your
> constants into classes, which works just as well. This avoids name
> conflicts.
> 
> Hope that answered your question.
> 
> 
> Tomi Kaistila
> PHP Developer
> 

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



Re: [PHP] Should I put pictures into a database?

2007-11-29 Thread Robin Vickery
On 28/11/2007, AmirBehzad Eslami <[EMAIL PROTECTED]> wrote:
> On Wednesday 21 November 2007 03:14:43 Ronald Wiplinger wrote:
> > I have an application, where I use pictures. The size of the picture is
> > about 90kB and to speed up the preview, I made a thumbnail of each
> > picture which is about 2.5 to 5kB.
> > I use now a directory structure of   ../$a/$b/$c/
>
> I rather to store images on the file-system, since database is another
> level over the file-system. However, I still need to store a pointer for
> every image into the database. This leads to storing the file names
> twice: one time in file-system, and one time in db.
> Isn't this redundancy?

Think of it as a foreign key.

-robin

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



Re: [PHP] Instantiate phpmailer in a separate class?

2007-11-29 Thread Mike Yrabedra
on 11/29/07 1:53 AM, Jochem Maas at [EMAIL PROTECTED] wrote:

> Mike Yrabedra wrote:
>> Hello,
>> 
>> I want to have a class send some emails.
>> 
>> I wanted to use the excellent phpMailer class to do this.
>> 
>> What is the proper way to use the phpMailer class from within a method of a
>> separate class?
> 
> the same way you would use it outside of a method of a class.
> 
> 
> class Foo {
> function bar() {
> $mailer = new phpMailer;
> // do stuff with mailer.
> }
> }
> 
> 
> now your Foo class might want to make use of the $mailer object from within
> more than one method - in this case you can consider using a property of your
> Foo instances.
> 
> class Foo {
> private $mailer;
> function __construct() {
> $this->mailer = new phpMailer;
> }
> function bar() {
> $this->mailer->clearAddresses();
> } 
> function bar() {
> $this->mailer->Send();
> }
> }
> 
> 
>> 
>> 
> 


Very kewl. Thank you.


-- 
Mike B^)>

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:
I got different portions of code only used for certain purposes (who don't 
;-)?). But what, in your opinion (better: in your experience) would be the 
best regarding script-performance: Putting each code-portion in a separate 
file and include it if required, putting it in a constant-dependent 
if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) 


defining functions or classes conditionally is not recommended, because it
means they can only be defined at runtime and not compile time ... which will
kill any op-code caching you might have in place or use in future (e.g. 
php.net/apc)


I'm not completely sure, but I think you're wrong there. Removing the 
condition in the example above will not affect any opcode caching since 
PHP cannot determine the result of that conditional until runtime.


To the OP: You're treading on the dangerous ground of premature 
optimisation. In the grand scheme of things the time taken for PHP to 
compile your scripts is tiny compared to the time it will take to run 
it. And as mentioned there are several ways to cache the compilation 
output which turns that tiny time into a negligible time.


Worry about the structure and maintainability of your app rather than 
thinking about how fast it is. Once you have the app doing something 
useful you can start to think about how to make it do it quickly.


-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
> Jochem Maas wrote:
>> [EMAIL PROTECTED] wrote:
>>> I got different portions of code only used for certain purposes (who
>>> don't ;-)?). But what, in your opinion (better: in your experience)
>>> would be the best regarding script-performance: Putting each
>>> code-portion in a separate file and include it if required, putting
>>> it in a constant-dependent if-structure (if (defined('FOO') && FOO)
>>> {class foo{}; function foo(); ...}) 
>>
>> defining functions or classes conditionally is not recommended,
>> because it
>> means they can only be defined at runtime and not compile time ...
>> which will
>> kill any op-code caching you might have in place or use in future
>> (e.g. php.net/apc)
> 
> I'm not completely sure, but I think you're wrong there. Removing the
> condition in the example above will not affect any opcode caching since
> PHP cannot determine the result of that conditional until runtime.

one of us is reading the other's post incorrectly - I have a feeling we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of op-code caching
as compiletime definitions.

or not?

> 
> To the OP: You're treading on the dangerous ground of premature
> optimisation. In the grand scheme of things the time taken for PHP to
> compile your scripts is tiny compared to the time it will take to run
> it. And as mentioned there are several ways to cache the compilation
> output which turns that tiny time into a negligible time.
> 
> Worry about the structure and maintainability of your app rather than
> thinking about how fast it is. Once you have the app doing something
> useful you can start to think about how to make it do it quickly.
> 
> -Stut
> 


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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jo chem baas wrote:

Stut wrote:

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:

I got different portions of code only used for certain purposes (who
don't ;-)?). But what, in your opinion (better: in your experience)
would be the best regarding script-performance: Putting each
code-portion in a separate file and include it if required, putting
it in a constant-dependent if-structure (if (defined('FOO') && FOO)
{class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended,
because it
means they can only be defined at runtime and not compile time ...
which will
kill any op-code caching you might have in place or use in future
(e.g. php.net/apc)

I'm not completely sure, but I think you're wrong there. Removing the
condition in the example above will not affect any opcode caching since
PHP cannot determine the result of that conditional until runtime.


one of us is reading the other's post incorrectly - I have a feeling we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of op-code caching
as compiletime definitions.

or not?


Not ;). There is no such thing as a compile-time definition in PHP.

Whether there is conditional definition or not, the opcode cache will 
look the same. The reason for this is that function and class 
definitions happen at runtime not compile time. This would have to be 
the case for conditional definition to work at all, since the compiler 
cannot determine the value of a condition at compile-time.


-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
> Jo chem baas wrote:
>> Stut wrote:
>>> Jochem Maas wrote:
 [EMAIL PROTECTED] wrote:
> I got different portions of code only used for certain purposes (who
> don't ;-)?). But what, in your opinion (better: in your experience)
> would be the best regarding script-performance: Putting each
> code-portion in a separate file and include it if required, putting
> it in a constant-dependent if-structure (if (defined('FOO') && FOO)
> {class foo{}; function foo(); ...}) 
 defining functions or classes conditionally is not recommended,
 because it
 means they can only be defined at runtime and not compile time ...
 which will
 kill any op-code caching you might have in place or use in future
 (e.g. php.net/apc)
>>> I'm not completely sure, but I think you're wrong there. Removing the
>>> condition in the example above will not affect any opcode caching since
>>> PHP cannot determine the result of that conditional until runtime.
>>
>> one of us is reading the other's post incorrectly - I have a feeling
>> we are
>> both trying to say the same thing.
>>
>> namely runtime class definitions don't have the same benefit of
>> op-code caching
>> as compiletime definitions.
>>
>> or not?
> 
> Not ;). There is no such thing as a compile-time definition in PHP.
> 
> Whether there is conditional definition or not, the opcode cache will
> look the same. The reason for this is that function and class
> definitions happen at runtime not compile time. This would have to be
> the case for conditional definition to work at all, since the compiler
> cannot determine the value of a condition at compile-time.

okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}

> 
> -Stut
> 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

Stut wrote:

Jo chem baas wrote:

Stut wrote:

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:

I got different portions of code only used for certain purposes (who
don't ;-)?). But what, in your opinion (better: in your experience)
would be the best regarding script-performance: Putting each
code-portion in a separate file and include it if required, putting
it in a constant-dependent if-structure (if (defined('FOO') && FOO)
{class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended,
because it
means they can only be defined at runtime and not compile time ...
which will
kill any op-code caching you might have in place or use in future
(e.g. php.net/apc)

I'm not completely sure, but I think you're wrong there. Removing the
condition in the example above will not affect any opcode caching since
PHP cannot determine the result of that conditional until runtime.

one of us is reading the other's post incorrectly - I have a feeling
we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of
op-code caching
as compiletime definitions.

or not?

Not ;). There is no such thing as a compile-time definition in PHP.

Whether there is conditional definition or not, the opcode cache will
look the same. The reason for this is that function and class
definitions happen at runtime not compile time. This would have to be
the case for conditional definition to work at all, since the compiler
cannot determine the value of a condition at compile-time.


okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}


Hopefully he's reading and will be able to give us a definitive answer.

I'm going by my experience of stepping through code with Zend Studio, 
but it's possible (probably likely) that ZE does something slightly 
different when a debugger is attached.


-Stut

--
http://stut.net/

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



[PHP] Re: Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
Thank you for the answers.

My abstract:

Use separate files for separate code. Easy to maintain, no real loss in 
performance. That's fine, as I'm just doing so (like if I need a database 
abstraction, I include dbas.php and if dbas.php needs some miscellaneous 
functionality, it includes misc.php by itself - so no worry for me to think 
about the dependencies of the scripts). Yes, that makes use of 
require_once() et al., but as I didn't plan to use something like ACP, it 
seems to be no problem so far.

Use absolute pathnames when including. That's too what I do, as I don't want 
scripts to be found accidentally - see the thread about inlcuding config.php 
for that ;-).

Caching code might be another possibility for gaining speed - I will think 
about that later, thank you for the hints.

And last but not least: First make your code work in a proper and 
maintainable way. Then think (and ask) for speed. And don't expect people to 
assume you have done it this way ;-).

If someone wants to complete this abstract, it would be appreciated, 
otherwise I'm done.

Thank you again!
Thomas 


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



[PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread news_yodpeirs
For some simple applications I use a function to collect values in a static
variable and to return them when called in a special way, just like this
(fairly senseless) example:
  function example($elem='') {
static $store = array();
if (!func_num_args()) return($store);
... do something with $elem ...
$store[] = $elem;
  }
I would call this a singleton-micro-class, as it works like a class with
data and methods, but there is always only one of it, having only one
method.

Why do I? Because I dont need to worry about variablescope as if I would use
global variables and I dont have to initialize an object before the first
call (with the scope-problem again). I simply can call it everywhere and
everytime.

Do you have any comments to this approach?

Thomas

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



Re: [PHP] Curl doesn't handle memory stream

2007-11-29 Thread Peter Smit
On Nov 27, 2007 11:43 PM, Peter Smit <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've got quite a strange problem with the curl library.
>
> The following code does output Content||\Content instead of
> Content|example.orgoutput|\Content
>
> $c = curl_init("http://example.com";);
> $st = fopen("php://memory", "r+");
>
> curl_setopt($c, CURLOPT_FILE, $st);
>
> if(!curl_exec($c)) die ("error: ".curl_error($c));
>
> rewind($st);
> echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> fclose($st);
>
>
> If I use a file stream instead it works as expected:
>
> $c = curl_init("http://example.com";);
>
> $file = "/tmp/phptest".rand()."";
> touch($file);
> $st = fopen($file, "r+");
>
> curl_setopt($c, CURLOPT_FILE, $st);
>
> if(!curl_exec($c)) die ("error: ".curl_error($c));
>
> rewind($st);
> echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> fclose($st);
> unlink($file);
>
>
> What's the problem? Does PHP not support memory streams in Curl?
>
> Peter
>


Hello,

I don't know or it's allowed to kick thread, but I give it a try.
Does somebody have any idea why the Curl extension doesn't handle
memory streams?

Regards,

Peter

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



[PHP] variable array name

2007-11-29 Thread Mark Head
I seem to be having a problem in assigning a value to an array where the 
array is called dynamically.

e.g. the physical name for the array is "my_array", so:
my_array[1] = "test";
works fine.

$array_name = "my_array";
$array_name[1] = "test";
does not work.

I have tried $$array_name[1] = "test"; but to no avail.

Any Ideas?

Cheers,

Mark 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Paul Scott

On Thu, 2007-11-29 at 13:51 +0100, Jochem Maas wrote:
> okay, but I was just paraphrasing the man Rasmus, although I admit I
> may
> have misinterpreted (or misundersstood the 'why') - thought I pretty
> sure
> he has written on a number of occasions that code like the following
> sucks
> for op-code caches and should be avoided:
> 
> if (foo()) {
>   class Foo { }
> }
> 

As I have always understood it, the heavyness only really comes in when
there are conditional includes or requires

if (foo()) {
require_once('foo_class_inc.php');
}
else {
// ...
}

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

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

Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
> Jochem Maas wrote:
>> Stut wrote:
>>> Jo chem baas wrote:

^- wtf happened here? :-) it's quite funny if you know dutch :-)

...

>>> Whether there is conditional definition or not, the opcode cache will
>>> look the same. The reason for this is that function and class
>>> definitions happen at runtime not compile time. This would have to be
>>> the case for conditional definition to work at all, since the compiler
>>> cannot determine the value of a condition at compile-time.
>>
>> okay, but I was just paraphrasing the man Rasmus, although I admit I may
>> have misinterpreted (or misundersstood the 'why') - thought I pretty sure
>> he has written on a number of occasions that code like the following
>> sucks
>> for op-code caches and should be avoided:
>>
>> if (foo()) {
>> class Foo { }
>> }
> 
> Hopefully he's reading and will be able to give us a definitive answer.

here is the post that I was recalling:

http://lists.nyphp.org/pipermail/talk/2006-March/017676.html

I believe his third point validates what I was saying although I did
make a bit of a mess with regard of my use of terminology.

> 
> I'm going by my experience of stepping through code with Zend Studio,
> but it's possible (probably likely) that ZE does something slightly
> different when a debugger is attached.
> 
> -Stut
> 

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



[PHP] Variable Names

2007-11-29 Thread Shaun
Hi,

I seem to be having a problem in assigning a value to an array where the
array is called dynamically.

e.g. the physical name for the array is "my_array", so:
my_array[1] = "test";
works fine.

$array_name = "my_array";
$array_name[1] = "test";
does not work.

I have tried $$array_name[1] = "test"; but to no avail.

Here is my code

/**
 * Adds any posted values from the application form to the session
 */
 function add_form_to_session() {
  foreach ($_POST AS $key => $value) {
   if (is_array($value)) {
foreach ($value AS $subkey => $subvalue) {
 $_SESSION['ses-app-form']->$key[$subkey] = $subvalue;
 //echo "value: ".$key."";
}
   }

   else {
$_SESSION['ses-app-form']->$key = $value;
//echo "value: ".$key." = ".$value."";
   }
  }
 }


Any Ideas?

Cheers,

Shaun

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
> Just to be curious:
> 
> when something like
> 
> if (defined('FOO') && FOO) {
>   class foo{};
>   function foo(){};
> }
> 
> is parsed and FOO is not defined, will the code inside be parsed 
> nevertheless? Or is anything inside skipped, leading to a (fragments of 
> microseconds) faster handling of the code? Thus to go to my original 
> question concerning speed: Would I save time with this construct as I would 
> save it with skipping an include()?

no. regardless of whether that is actually true, still no.
it's crufty.

they have a word very suitable to this situation in dutch 'mierenneuken',
personally I'd stick with pretty girls.

> 
> Thomas 
> 

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



AW: [PHP] Variable Names

2007-11-29 Thread Frank Ruske
 "bar");

var_dump($my_array);
?>
array(1) { [0]=>  string(3) "bar" }


Regards Frank

-Ursprüngliche Nachricht-
Von: Shaun [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 29. November 2007 13:57
An: php-general@lists.php.net
Betreff: [PHP] Variable Names


Hi,

I seem to be having a problem in assigning a value to an array where the
array is called dynamically.

e.g. the physical name for the array is "my_array", so:
my_array[1] = "test";
works fine.

$array_name = "my_array";
$array_name[1] = "test";
does not work.

I have tried $$array_name[1] = "test"; but to no avail.

Here is my code

/**
 * Adds any posted values from the application form to the session
 */
 function add_form_to_session() {
  foreach ($_POST AS $key => $value) {
   if (is_array($value)) {
foreach ($value AS $subkey => $subvalue) {
 $_SESSION['ses-app-form']->$key[$subkey] = $subvalue;
 //echo "value: ".$key."";
}
   }

   else {
$_SESSION['ses-app-form']->$key = $value;
//echo "value: ".$key." = ".$value."";
   }
  }
 }


Any Ideas?

Cheers,

Shaun

-- 
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



AW: [PHP] Variable Names

2007-11-29 Thread Frank Ruske
 "bar");

var_dump($my_array);
?>
array(1) { [0]=>  string(3) "bar" }


Regards Frank

-Ursprüngliche Nachricht-
Von: Shaun [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 29. November 2007 13:57
An: php-general@lists.php.net
Betreff: [PHP] Variable Names


Hi,

I seem to be having a problem in assigning a value to an array where the
array is called dynamically.

e.g. the physical name for the array is "my_array", so:
my_array[1] = "test";
works fine.

$array_name = "my_array";
$array_name[1] = "test";
does not work.

I have tried $$array_name[1] = "test"; but to no avail.

Here is my code

/**
 * Adds any posted values from the application form to the session
 */
 function add_form_to_session() {
  foreach ($_POST AS $key => $value) {
   if (is_array($value)) {
foreach ($value AS $subkey => $subvalue) {
 $_SESSION['ses-app-form']->$key[$subkey] = $subvalue;
 //echo "value: ".$key."";
}
   }

   else {
$_SESSION['ses-app-form']->$key = $value;
//echo "value: ".$key." = ".$value."";
   }
  }
 }


Any Ideas?

Cheers,

Shaun

-- 
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: Variable Names

2007-11-29 Thread news_yodpeirs
The manual says:

In order to use variable variables with arrays, you have to resolve an 
ambiguity problem. That is, if you write $$a[1] then the parser needs to 
know if you meant to use $a[1] as a variable, or if you wanted $$a as the 
variable and then the [1] index from that variable. The syntax for resolving 
this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second.

Does this help you?

Thomas 

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



Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread Zoltán Németh
2007. 11. 29, csütörtök keltezéssel 14.18-kor [EMAIL PROTECTED]
ezt írta:
> For some simple applications I use a function to collect values in a static
> variable and to return them when called in a special way, just like this
> (fairly senseless) example:
>   function example($elem='') {
> static $store = array();

AFAIK the above line should cause an error on the second run of the
function, as you declare the same static variable for the second time.

or am I wrong?

greets
Zoltán Németh

> if (!func_num_args()) return($store);
> ... do something with $elem ...
> $store[] = $elem;
>   }
> I would call this a singleton-micro-class, as it works like a class with
> data and methods, but there is always only one of it, having only one
> method.
> 
> Why do I? Because I dont need to worry about variablescope as if I would use
> global variables and I dont have to initialize an object before the first
> call (with the scope-problem again). I simply can call it everywhere and
> everytime.
> 
> Do you have any comments to this approach?
> 
> Thomas
> 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

Stut wrote:

Jochem Maas wrote:

Stut wrote:

Jo chem baas wrote:


^- wtf happened here? :-) it's quite funny if you know dutch :-)


Pass. Looking back it looks like it happened one of the times I replied. 
Didn't do it on purpose, honest! ;)



Whether there is conditional definition or not, the opcode cache will
look the same. The reason for this is that function and class
definitions happen at runtime not compile time. This would have to be
the case for conditional definition to work at all, since the compiler
cannot determine the value of a condition at compile-time.

okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following
sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}

Hopefully he's reading and will be able to give us a definitive answer.


here is the post that I was recalling:

http://lists.nyphp.org/pipermail/talk/2006-March/017676.html

I believe his third point validates what I was saying although I did
make a bit of a mess with regard of my use of terminology.


Hmm, Rasmus seems to be saying that opcode caches have a way to optimise 
the definition of entities, and by defining them conditionally they 
can't make use of that. That kinda makes sense, but I'd expect the 
difference to be negligible unless you're talking about a file with 
thousands upon thousands of definitions.


Anyhoo, back to the coalface.

-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
Just to be curious:

when something like

if (defined('FOO') && FOO) {
  class foo{};
  function foo(){};
}

is parsed and FOO is not defined, will the code inside be parsed 
nevertheless? Or is anything inside skipped, leading to a (fragments of 
microseconds) faster handling of the code? Thus to go to my original 
question concerning speed: Would I save time with this construct as I would 
save it with skipping an include()?

Thomas 

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



Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread news_yodpeirs
From: "Zoltán Németh" <[EMAIL PROTECTED]>
>>   function example($elem='') {
>> static $store = array();
>
> AFAIK the above line should cause an error on the second run of the
> function, as you declare the same static variable for the second time.
>
> or am I wrong?

I think so - otherwise static Variables would be quite senseless. The line
starting with static is (so do I think) once evaluated at compile-time or at
the first run and the ignored.

Thomas 

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



Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
> From: "Zoltán Németh" <[EMAIL PROTECTED]>
>>>   function example($elem='') {
>>> static $store = array();
>> AFAIK the above line should cause an error on the second run of the
>> function, as you declare the same static variable for the second time.
>>
>> or am I wrong?

indeed you are :-)

> 
> I think so - otherwise static Variables would be quite senseless. The line
> starting with static is (so do I think) once evaluated at compile-time or at
> the first run and the ignored.

I believe it's a compile time definition ... which is the reason you can only
initialize static vars with scalar values (and not the result of expressions or
resources or objects, etc)


> 
> Thomas 
> 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
> they have a word very suitable to this situation in dutch 'mierenneuken',
> personally I'd stick with pretty girls.

OT: Couldn't translate that in german, the nearest approach seems to be 
"Haarspalterei" but unfortunately for me this seems not to match the 
situation. And it doesn't meet pretty girls too :-D.

But so in fact conditional definitions are absolutely useless - apart from 
giving the parser some work without using it's outcome?

Thomas 



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



[PHP] One more data formatting question

2007-11-29 Thread Jon Westcot
Hi all:

I'm trying to parse out some HTML code back into "regular" string values 
and I keep getting tripped up by the non-breaking space value ( ).  I see 
that html_decode_entities() can be used to convert this back to a viewable 
space, but the documentation tells me that the space value it uses is not the 
same as a TRIMable space (i.e., ASCII 32).

Is there a quick, fast, and easily implemented way to convert any 
non-breaking space found in a string back to the ASCII 32 space value?  I 
suspect that one of those amazing POSIX expressions could do it, but I'm having 
trouble wrapping my head around them at this early hour.

Any help you all can provide will be extremely appreciated!

Thanks,

Jon


Re: [PHP] Dynamic Display of Images Stored in DB

2007-11-29 Thread David Giragosian
On 11/28/07, Chris <[EMAIL PROTECTED]> wrote:
>
>
> > In my solution, I use two scripts. One for showing the image true size
> > and another for generating a thumbnail -- I may be wrong, but I think
> > it's better to generate a thumbnail as needed on the fly than it is to
> > store both images (large and thumbnail) in the dB.
>
> Cache it on the filesystem even if it's for a short time (of course if
> the image is updated elsewhere the cache needs to be cleared as well..).
>
>
> 
> $file = '/path/to/cache/file.jpg';
> if (file_exists($file)) {
>   if (filemtime($file) > strtotime('-30 minutes')) {
> $fp = fopen($file, 'rb');
> fpassthru($fp);
> exit;
>   }
>
>   // the file is older than 30 minutes, kill it and start again.
>   unlink($file);
> }
>
> // continue creating your thumbnail.
>
> $fp = fopen('/path/to/cache/' . $filename, 'wb');
> fputs($fp, $imagecontents);
> fclose($fp);
>
> // display image
>
> --


Thanks for all the suggestions, guys. I was really trying to understand,
through extending it, the code from the reference (
http://www.wellho.net/solutions/php-example-php-form-image-upload-store-in-mysql-database-retreive.html
 ).

David


Re: [PHP] problem with url_fopen on free hosting environment

2007-11-29 Thread Samuel Vogel

Ok, I did find a solution by accident.
I just blocked all tcp requests on port 80 and 443 comming from my own 
outside IP. Since I have a couple of servers, I just dropped the 
following into rc.local on all of them:


# Blocking url_fopen requests
ownip=`curl -s http://checkip.dyndns.org | awk '{print $6}' | awk ' 
BEGIN { FS = "<" } { print $1 } '`

iptables -A INPUT -s $ownip -p tcp --dport 80 -j DROP
iptables -A INPUT -s $ownip -p tcp --dport 443 -j DROP

Maybe this helps somebody :)

Regards,
Samy

Samuel Vogel schrieb:

Thanks for the infos.
I read through the very interesting post, but I did not find it to be 
a solution for my problem.
I tried to limit connections with iptables, but it did not work out. 
I'm not an expert at this, I tried like it is described here:

http://www.linux-noob.com/forums/index.php?showtopic=1829

I know it just limits new connections, and I thought this would work 
out, but it didn't. Should I try to limit all connections?


Also it makes me wonder why mod_evasive for apache does not block this.
I will probably try to come up with a solution by using mod_security. 
But it would be much nicer if it would work on the iptables level.


Regards,
Samy

Andrés Robinet schrieb:


Hi Samuel,

 

I found this forum topic the other day http://uclue.com/?xq=874, and 
I thought it's pretty nice as a start/overview. There's also 
mod_bandwidth for Apache, not included in the aforementioned topic.


We are not currently having an issue with bandwidth and/or bots 
causing overload in the domains hosted with us, so I can't speak 
>from our experience with those apache modules. All of our hosting 
clients are known by us, and are not constantly changing (as it would 
be the case in a free hosting environment). So, these kind of issues 
are rare for us,  easily identifiable, and from external sources. 
None of our clients will try to bypass open_base_dir, or safe_mode, 
or allow_url_fopen.


If all of these apache modules are not doing their job and apache is 
still overworked... then either they need a tune up in their 
configuration or there must be something else behind the scenes and 
you'd better off checking your firewall ruleset or a kernel 
vulnerability. Probably you'll need to tackle the problem yet one 
layer down (firewall), but I'd say first exhaust all choices in the 
layer you are working on right now.


Also.. don't forget about mod_security and the like. You could try a 
filter on headers. First, do a unit test and check what HTTP_REFERER, 
HTTP_USER_AGENT, REMOTE_ADDR, etc look like for a self-calling 
script. So, if, say, the user agent is "X" and the local IP 
address is the same as the remote ip address then you invalidate the 
request for that particular domain.


Ok... hope you get to the solution, and then let us know on the 
mailing list


 


Rob



Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
cid:000701c7e78a$801a5160$0200a8c0@SAINTTHERESA



5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, 
FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 |
Email: [EMAIL PROTECTED] ** * | MSN 
Chat: [EMAIL PROTECTED]  * |  SKYPE: 
*bestplace* |  Web: *bestplace.biz*   | Web: 
*seo-diy.com

 *

Confidentiality:
"All information in this email message, including images, 
attachments, contains confidential and proprietary information of 
BESTPLACE CORPORATION and should only be used or serves for the 
intended purpose and should not be copied, used or disclosed to 
anyone other than the sole recipient of this e-mail message."






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



Re: [PHP] variable array name

2007-11-29 Thread Daniel Brown
On Nov 29, 2007 7:47 AM, Mark Head <[EMAIL PROTECTED]> wrote:
> I seem to be having a problem in assigning a value to an array where the
> array is called dynamically.
>
> e.g. the physical name for the array is "my_array", so:
> my_array[1] = "test";
> works fine.
>
> $array_name = "my_array";
> $array_name[1] = "test";
> does not work.
>
> I have tried $$array_name[1] = "test"; but to no avail.
>
> Any Ideas?
>
> Cheers,
>
> Mark
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>




-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

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



Re: [PHP] One more data formatting question

2007-11-29 Thread T . Lensselink
On Thu, 29 Nov 2007 07:53:56 -0700, "Jon Westcot" <[EMAIL PROTECTED]> wrote:
> Hi all:
> 
> I'm trying to parse out some HTML code back into "regular" string
> values and I keep getting tripped up by the non-breaking space value
> ( ).  I see that html_decode_entities() can be used to convert this
> back to a viewable space, but the documentation tells me that the space
> value it uses is not the same as a TRIMable space (i.e., ASCII 32).
> 
> Is there a quick, fast, and easily implemented way to convert any
> non-breaking space found in a string back to the ASCII 32 space value?  I
> suspect that one of those amazing POSIX expressions could do it, but I'm
> having trouble wrapping my head around them at this early hour.
> 
> Any help you all can provide will be extremely appreciated!
> 
> Thanks,
> 
> Jon

str_replace should do the trick.

str_replace(' ', chr(32), $string);
or
str_replace(' ', ' ', $string);

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



[PHP] Re: One more data formatting question

2007-11-29 Thread news_yodpeirs
How about
  $foo = str_replace(' ','',$foo);
?

Or could there be an ' ' in a context where it shouldn't be replaced?

Thomas 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread T . Lensselink
On Thu, 29 Nov 2007 14:54:43 +0100, Jochem Maas <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
>> Just to be curious:
>>
>> when something like
>>
>> if (defined('FOO') && FOO) {
>>   class foo{};
>>   function foo(){};
>> }
>>
>> is parsed and FOO is not defined, will the code inside be parsed
>> nevertheless? Or is anything inside skipped, leading to a (fragments of
>> microseconds) faster handling of the code? Thus to go to my original
>> question concerning speed: Would I save time with this construct as I
> would
>> save it with skipping an include()?
> 
> no. regardless of whether that is actually true, still no.
> it's crufty.
> 
> they have a word very suitable to this situation in dutch 'mierenneuken',
> personally I'd stick with pretty girls.

mierenneuker :)

Pretty girls over crufty code any day of the week!

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



Re: [PHP] One more data formatting question [SOLVED]

2007-11-29 Thread Jon Westcot
Hi:

Thanks for the answer!  That worked exactly as I needed it to work!

Jon

- Original Message - 
From: "T.Lensselink" <[EMAIL PROTECTED]>
To: "Jon Westcot" <[EMAIL PROTECTED]>
Cc: "PHP General" 
Sent: Thursday, November 29, 2007 8:17 AM
Subject: Re: [PHP] One more data formatting question


On Thu, 29 Nov 2007 07:53:56 -0700, "Jon Westcot" <[EMAIL PROTECTED]> wrote:
> Hi all:
> 
> I'm trying to parse out some HTML code back into "regular" string
> values and I keep getting tripped up by the non-breaking space value
> ( ).  I see that html_decode_entities() can be used to convert this
> back to a viewable space, but the documentation tells me that the space
> value it uses is not the same as a TRIMable space (i.e., ASCII 32).
> 
> Is there a quick, fast, and easily implemented way to convert any
> non-breaking space found in a string back to the ASCII 32 space value?  I
> suspect that one of those amazing POSIX expressions could do it, but I'm
> having trouble wrapping my head around them at this early hour.
> 
> Any help you all can provide will be extremely appreciated!
> 
> Thanks,
> 
> Jon

str_replace should do the trick.

str_replace(' ', chr(32), $string);
or
str_replace(' ', ' ', $string);

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



Re: [PHP] Curl doesn't handle memory stream

2007-11-29 Thread Nathan Nobbe
On Nov 29, 2007 7:56 AM, Peter Smit <[EMAIL PROTECTED]> wrote:

> On Nov 27, 2007 11:43 PM, Peter Smit <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I've got quite a strange problem with the curl library.
> >
> > The following code does output Content||\Content instead of
> > Content|example.orgoutput|\Content
> >
> > $c = curl_init("http://example.com";);
> > $st = fopen("php://memory", "r+");
> >
> > curl_setopt($c, CURLOPT_FILE, $st);
> >
> > if(!curl_exec($c)) die ("error: ".curl_error($c));
> >
> > rewind($st);
> > echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> > fclose($st);
> >
> >
> > If I use a file stream instead it works as expected:
> >
> > $c = curl_init("http://example.com";);
> >
> > $file = "/tmp/phptest".rand()."";
> > touch($file);
> > $st = fopen($file, "r+");
> >
> > curl_setopt($c, CURLOPT_FILE, $st);
> >
> > if(!curl_exec($c)) die ("error: ".curl_error($c));
> >
> > rewind($st);
> > echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> > fclose($st);
> > unlink($file);
>

im curious to know where you discovered
php://memory
was a valid stream; i looked through the online manual and found no
reference to it.
nor did i find anything from google.  i did encounter it in the php source,
but with no
useful documentation.
a reference of all the streams that are valid with the php:// scheme would
be helpful.

getting to your problem, i think this could perhaps be a bug.
you might file a bug report and post your code along with it; unless
somebody has a
better idea ;)

-nathan


Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Larry Garfield
On Thursday 29 November 2007, Jochem Maas wrote:

> okay, but I was just paraphrasing the man Rasmus, although I admit I may
> have misinterpreted (or misundersstood the 'why') - thought I pretty sure
> he has written on a number of occasions that code like the following sucks
> for op-code caches and should be avoided:
>
> if (foo()) {
>   class Foo { }
> }

That's bad because the compiler will *still* parse and compile class Foo(), 
but give it some ridiculous internal name so that it's inaccessible.  It will 
then, at runtime, conditionally give it a real name so that it then becomes 
accessible.  You'll still have the same cost to parse and compile class Foo() 
either way.  There is no savings in either compile time or memory use.

if (foo()) {
   include('foo.php');
}

This will make baby opcode cache cry, from what I understand, but will not 
balloon the memory usage the way the former code will.  In practice, though, 
a modular, pluggable system (most of what I use) is going to end up having 
conditional includes no matter what you do so I generally don't pay much 
attention to that type of optimization, since it's irrelevant to me anyway.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 12:13 +, Stut wrote:
>
> Not ;). There is no such thing as a compile-time definition in PHP.

There certainly is...



Now, I'm not necessarily advocating this style of compatibility
programming, but I remember seeing something like it in PEAR. I think it
might have been the pear SOAP classes where the classes had to be
declared dynamically.

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] Curl doesn't handle memory stream

2007-11-29 Thread Peter Smit
On Nov 29, 2007 5:18 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> On Nov 29, 2007 7:56 AM, Peter Smit <[EMAIL PROTECTED]> wrote:
>
> >
> >
> >
> > On Nov 27, 2007 11:43 PM, Peter Smit <[EMAIL PROTECTED]> wrote:
> > > Hello,
> > >
> > > I've got quite a strange problem with the curl library.
> > >
> > > The following code does output Content||\Content instead of
> > > Content|example.orgoutput|\Content
> > >
> > > $c = curl_init("http://example.com ");
> > > $st = fopen("php://memory", "r+");
> > >
> > > curl_setopt($c, CURLOPT_FILE, $st);
> > >
> > > if(!curl_exec($c)) die ("error: ".curl_error($c));
> > >
> > > rewind($st);
> > > echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> > > fclose($st);
> > >
> > >
> > > If I use a file stream instead it works as expected:
> > >
> > > $c = curl_init(" http://example.com";);
> > >
> > > $file = "/tmp/phptest".rand()."";
> > > touch($file);
> > > $st = fopen($file, "r+");
> > >
> > > curl_setopt($c, CURLOPT_FILE, $st);
> > >
> > > if(!curl_exec($c)) die ("error: ".curl_error($c));
> > >
> > > rewind($st);
> > > echo "Content|".htmlspecialchars(stream_get_contents($st))."|/Content";
> > > fclose($st);
> > > unlink($file);
>
> im curious to know where you discovered
> php://memory
> was a valid stream; i looked through the online manual and found no
> reference to it.
> nor did i find anything from google.  i did encounter it in the php source,
> but with no
> useful documentation.
> a reference of all the streams that are valid with the php:// scheme would
> be helpful.
>
> getting to your problem, i think this could perhaps be a bug.
> you might file a bug report and post your code along with it; unless
> somebody has a
> better idea ;)
>
> -nathan
>

This reference to php:// streams you can find on
http://www.php.net/manual/en/wrappers.php.php . If nobody has a
solution I think I'll report it as a bug tomorrow.

Peter

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 16:49 +, Stut wrote:
> Robert Cummings wrote:
> > On Thu, 2007-11-29 at 12:13 +, Stut wrote:
> >> Not ;). There is no such thing as a compile-time definition in PHP.
> > 
> > There certainly is...
> > 
> >  > 
> > if( !function_exists( 'file_put_contents' ) )
> > {
> > $def = <<<_
> >
> > function file_put_contents
> > ( \$filename, \$data, \$flags=0, \$context=null )
> > {
> > // :)
> > }
> > _;
> >   
> > eval( $def );
> > 
> > }
> > 
> > ?>
> > 
> > Now, I'm not necessarily advocating this style of compatibility
> > programming, but I remember seeing something like it in PEAR. I think it
> > might have been the pear SOAP classes where the classes had to be
> > declared dynamically.
> 
> That's a runtime definition. It has to be. The function_exists function 
> *cannot* be "run" at compile-time to see what the result is, so it must 
> happen at runtime.

Bleh, just read your comments and then read the comment I quoted and I
find myself needing a morning wakeup slap :) Your comment at the top
says compile-time, not run-time. I'm going to go find a big rock *hehe*.

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] Dynamic Display of Images Stored in DB

2007-11-29 Thread Børge Holen
On Thursday 29 November 2007 06:03:32 Chris wrote:
> > In my solution, I use two scripts. One for showing the image true size
> > and another for generating a thumbnail -- I may be wrong, but I think
> > it's better to generate a thumbnail as needed on the fly than it is to
> > store both images (large and thumbnail) in the dB.
>
> Cache it on the filesystem even if it's for a short time (of course if
> the image is updated elsewhere the cache needs to be cleared as well..).
>
>
> 
> $file = '/path/to/cache/file.jpg';
> if (file_exists($file)) {
>if (filemtime($file) > strtotime('-30 minutes')) {
>  $fp = fopen($file, 'rb');
>  fpassthru($fp);
>  exit;
>}
>
>// the file is older than 30 minutes, kill it and start again.
>unlink($file);
> }
>
> // continue creating your thumbnail.
>
> $fp = fopen('/path/to/cache/' . $filename, 'wb');
> fputs($fp, $imagecontents);
> fclose($fp);
>
> // display image


Hell, I'm all ok with this method... but does (different) webhotells take into 
account the amount used with cache/temp files.
If so, some check should be used, and if not. Cache it all!, and remove the 
timelimit, some check for the change of image of course, but that all depends 
if you acctually change images from time to time..

>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/



-- 
---
Børge Holen
http://www.arivene.net

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Robert Cummings wrote:

On Thu, 2007-11-29 at 12:13 +, Stut wrote:

Not ;). There is no such thing as a compile-time definition in PHP.


There certainly is...

   
function file_put_contents

( \$filename, \$data, \$flags=0, \$context=null )
{
// :)
}
_;
  
eval( $def );


}

?>

Now, I'm not necessarily advocating this style of compatibility
programming, but I remember seeing something like it in PEAR. I think it
might have been the pear SOAP classes where the classes had to be
declared dynamically.


That's a runtime definition. It has to be. The function_exists function 
*cannot* be "run" at compile-time to see what the result is, so it must 
happen at runtime.


I think maybe the confusion is over terminology. In my mind Zend Studio 
would not let me step through a compile-time process, but it's looking 
likely that that's precisely what it's doing if I'm to believe 
everything I'm reading.


Here's what I see when a file is included... I can step through each 
function definition line (function ...), and at the same time it 
executes any inline code outside of the functions. That seems like a 
runtime process to me. If there is a function definition contained 
within the file, or a function defined within a function, the debugger 
does not hit that definition unless the condition matches or the 
function is called.


To me this indicates that PHP defines entities at run time. It's 
possible that it also defines them at compile-time, but I don't know the 
internals well enough to know.


-Stut

--
http://stut.net/

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



[PHP] Glob

2007-11-29 Thread Tom Chubb
Please can someone help me understand the following:
I have 4 images with a .jpg extension in a folder.
The following reads all four:
$files = glob("thumbs/{*.gif,*.jpg,}",GLOB_BRACE);

All good, however, I noticed that if the extension is in capital
letters, eg .JPG it doesn't work. Apparently this is because when
using *. in glob it's case-sensitive (I have RTFM/STFW)

So, I would expect the following to work, but it's reading each image twice!
$files = glob("thumbs/{*.gif,*.jpg,*.jpeg,*,png}",GLOB_BRACE);

What am I missing?

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



[PHP] dump a class

2007-11-29 Thread Alex Toro
Hello, I would like to know why when I print_r or var_dump an object I
get the private properties. I give you an example:

myPrivate; // Fatal error: Cannot access private property
test::$myPrivate in . that's OK!

echo '';
print_r($myTest);
#test Object
#(
#[myPrivate:private] => topsecret
#)
var_dump($myTest);
#object(test)#1 (1) {
#  ["myPrivate:private"]=>
#  string(9) "topsecret"
#}
echo '';

?>

A private member is suposed to be private, isn't it?

Alex

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



Re: [PHP] Glob

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 17:19 +, Tom Chubb wrote:
> Please can someone help me understand the following:
> I have 4 images with a .jpg extension in a folder.
> The following reads all four:
> $files = glob("thumbs/{*.gif,*.jpg,}",GLOB_BRACE);
> 
> All good, however, I noticed that if the extension is in capital
> letters, eg .JPG it doesn't work. Apparently this is because when
> using *. in glob it's case-sensitive (I have RTFM/STFW)
> 
> So, I would expect the following to work, but it's reading each image twice!
> $files = glob("thumbs/{*.gif,*.jpg,*.jpeg,*,png}",GLOB_BRACE);
> 
> What am I missing?

You have *,png when you should have *.png. The * is matching everything.

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] Glob

2007-11-29 Thread Tom Chubb
On 29/11/2007, Robert Cummings <[EMAIL PROTECTED]> wrote:
> On Thu, 2007-11-29 at 17:19 +, Tom Chubb wrote:
> > Please can someone help me understand the following:
> > I have 4 images with a .jpg extension in a folder.
> > The following reads all four:
> > $files = glob("thumbs/{*.gif,*.jpg,}",GLOB_BRACE);
> >
> > All good, however, I noticed that if the extension is in capital
> > letters, eg .JPG it doesn't work. Apparently this is because when
> > using *. in glob it's case-sensitive (I have RTFM/STFW)
> >
> > So, I would expect the following to work, but it's reading each image twice!
> > $files = glob("thumbs/{*.gif,*.jpg,*.jpeg,*,png}",GLOB_BRACE);
> >
> > What am I missing?
>
> You have *,png when you should have *.png. The * is matching everything.
>
> Cheers,
> Rob.
> --
> ...
> SwarmBuy.com - http://www.swarmbuy.com
>
>Leveraging the buying power of the masses!
> ...
>
Wll spotted Rob,
Thanks,

Tom

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



Re: [PHP] dump a class

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 18:16 +0100, Alex Toro wrote:
> Hello, I would like to know why when I print_r or var_dump an object I
> get the private properties. I give you an example:
> 
>  
> class test
> {
>   private $myPrivate = 'topsecret';
> }
> 
> $myTest = new test();
> 
> #echo $myTest->myPrivate; // Fatal error: Cannot access private property
> test::$myPrivate in . that's OK!
> 
> echo '';
> print_r($myTest);
> #test Object
> #(
> #[myPrivate:private] => topsecret
> #)
> var_dump($myTest);
> #object(test)#1 (1) {
> #  ["myPrivate:private"]=>
> #  string(9) "topsecret"
> #}
> echo '';
> 
> ?>
> 
> A private member is suposed to be private, isn't it?

It's private in the context of runtime requests to retrieve or set the
value via the normal methods for setting and retrieving data properties.
Most people use print_r() and var_dump() to debug their data structures,
in which case they certainly do want to see the private members. Even if
they were hidden you would find it to be absolutely necessary that they
be exposed when serialized, otherwise how could you properly
unserialize. Given that condition, does it matter that they are visible
via print_r() or var_dump() when another method for viewing them exists?

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



[PHP] WSDL Question

2007-11-29 Thread Jonathan Pitcher
For the lasts day I have been fighting with PHP, and WSDL calls to a thrid
party provider.

Here is what the call needs to look like:




root

IperiaTestOrg
false


SUBSCRIBER_DEFINED_TRANSFER_NUMBER
6179672983


TIMEZONE
US/CENTRAL






I can generate most of the code in fact I can generate all of it but the
Double service setting.

Here is my relevant PHP code.

$SDT = $portal->get_post('SDT');

$SDT = new SoapVar(array('ns1:type' => 'SUBSCRIBER_DEFINED_TRANSFER_ON',
'ns1:value' => $SDT), SOAP_ENC_OBJECT);

$setting_info = array(array('ns1:serviceSetting' => $SDT));

// Getting Iperia Soap Object ...

$soap_iperia = $portal->load_special_object('soap_iperia');


$find_account_obj->accountIdentifier = new SoapVar(array('ns1:account' =>
'root'), SOAP_ENC_OBJECT);


$find_account_obj->orgID = new SoapVar('IperiaTestOrg', XSD_STRING);

$find_account_obj->suspended = new SoapVar(0, XSD_BOOLEAN);

$find_account_obj->serviceSettingCollection = new SoapVar($setting_info,
SOAP_ENC_OBJECT);

$results = $soap_iperia->modifyOrganization($find_account_obj);

That generates the following xml.




root

IperiaTestOrg
false


SUBSCRIBER_DEFINED_TRANSFER_NUMBER
6179672983





The question I have is how do I add in the extra:



TIMEZONE
US/CENTRAL


I have tried a couple ways with no success ...

Any tips would be greatly appreciated.

Jonathan Pitcher

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



[PHP] Join question

2007-11-29 Thread tedd

Hi gang:

I'm trying to understand joins,

Here's the situation. I have two tables (user1, user2) in one database:

The common field between the two tables is "username". I want to take 
fields "login" and "password" from user2 and populate the same fields 
in user1.


Currently, the table user1 has 5303 entries, whereas user2 has 5909.

What I want at the end of this is for table user1 to have the same 
number of entries as table user2.


Now, how do I set up the query?

TIA for any suggestions.

Cheers,

tedd

PS: Side note -- will safe_mode ON cause problems with this?

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Join question

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 15:41 -0500, tedd wrote:
> Hi gang:
> 
> I'm trying to understand joins,
> 
> Here's the situation. I have two tables (user1, user2) in one database:
> 
> The common field between the two tables is "username". I want to take 
> fields "login" and "password" from user2 and populate the same fields 
> in user1.
> 
> Currently, the table user1 has 5303 entries, whereas user2 has 5909.
> 
> What I want at the end of this is for table user1 to have the same 
> number of entries as table user2.
> 
> Now, how do I set up the query?

INSERT INTO table1
(
login,
password
)
SELECT
T2.login,
T2.password
FROM
table2 AS T2
LEFT JOIN table1 as T1 ON
T1.login = T2.login
WHERE
T1.login IS NULL;

That should do it... off the top of my head :)

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] Join question

2007-11-29 Thread Daniel Brown
On Nov 29, 2007 3:41 PM, tedd <[EMAIL PROTECTED]> wrote:
> Hi gang:

Hi, Tedd.

> PS: Side note -- will safe_mode ON cause problems with this?

Negative.  I can't see any reason to even think so.  All safe_mode
does is check the UID/GID of the script to make sure it matches that
of the target file you're attempting to open.  Socket connections
don't count.

In the next few years, it won't make a difference, since safe_mode
has been removed as of PHP 6.0.0.  I believe the only components of
that to remain will be the open_basedir (which I think moves from
PHP_INI_SYSTEM to PHP_INI_ALL) and the disable_* parts.  Don't quote
me on that, though, since I'm too lazy to go look it up right now. ;-P

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

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



Re: [PHP] Join question

2007-11-29 Thread Wolf
 tedd <[EMAIL PROTECTED]> wrote: 
> Hi gang:
> 
> I'm trying to understand joins,
> 
> Here's the situation. I have two tables (user1, user2) in one database:
> 
> The common field between the two tables is "username". I want to take 
> fields "login" and "password" from user2 and populate the same fields 
> in user1.
> 
> Currently, the table user1 has 5303 entries, whereas user2 has 5909.
> 
> What I want at the end of this is for table user1 to have the same 
> number of entries as table user2.
> 
> Now, how do I set up the query?
> 
> TIA for any suggestions.
> 
> Cheers,
> 
> tedd
> 
> PS: Side note -- will safe_mode ON cause problems with this?
> 
You should be only "joined" on entries with the same amounts, so if username 
george is in both, it should join.

However if username george_by_george only exists in table 2, then you don't get 
a join happening.

What you would instead want to do is run a loop through the second table and 
grep the username against the first table.  If it exists, give them command to 
write table2.pass into table1.pass  
If it doesn't exist you want to write table2.user and table2.pass into table1

HTH,
Wolf

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



Re: [PHP] Join question

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 15:47 -0500, Wolf wrote:
>  tedd <[EMAIL PROTECTED]> wrote: 
> > Hi gang:
> > 
> > I'm trying to understand joins,
> > 
> > Here's the situation. I have two tables (user1, user2) in one database:
> > 
> > The common field between the two tables is "username". I want to take 
> > fields "login" and "password" from user2 and populate the same fields 
> > in user1.
> > 
> > Currently, the table user1 has 5303 entries, whereas user2 has 5909.
> > 
> > What I want at the end of this is for table user1 to have the same 
> > number of entries as table user2.
> > 
> > Now, how do I set up the query?
> > 
> > TIA for any suggestions.
> > 
> > Cheers,
> > 
> > tedd
> > 
> > PS: Side note -- will safe_mode ON cause problems with this?
> > 
> You should be only "joined" on entries with the same amounts, so if username 
> george is in both, it should join.
> 
> However if username george_by_george only exists in table 2, then you don't 
> get a join happening.
> 
> What you would instead want to do is run a loop through the second table and 
> grep the username against the first table.  If it exists, give them command 
> to write table2.pass into table1.pass  
> If it doesn't exist you want to write table2.user and table2.pass into table1

Grep? Loop? A single query will suffice. Also, he doesn't mention
wanting to clobber the passwords in table1 when the username does
already exist.

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



[PHP] Clowns à l'Hopital / php-general@lists.php.net : passez à l'action à travers eux !

2007-11-29 Thread =?ISO-8859-1?Q?Catapulte Freeware =AE
Si ce message ne s'affiche pas correctement : retrouvez-le en ligne ici : 
http://www.clown-hopital.com/interne/CAMPAGNE-N2007.htm
Conformément à la loi et aux règlements de la CNIL, les messages de prospection 
associatifs, politiques, caritatifs ou religieux sont seulement soumis à 
l'obligation d'accès aux données (comme les messages postaux) et ne sont pas 
considérés comme des messages de publicité commerciale.
si vous souhaitez ne plus être tenu au courant de nos activités : merci de 
retourner ce mail avec la mention "desabo" dans le sujet.
Votre adresse sera immédiatement et définitivement retirée de notre base.

Campagne Noël 2007
message de l'association d'intérêt général
"Clowns Z'Hôpitaux", les Coeurs visiteurs
Un chaleureux MERCI à celles et ceux qui ont déjà répondu à nos précédents 
appels !

Agissez à travers nous en soutenant nos interventions :
Garches, La Rochelle , Lyon, Maurepas, Mende, Périgueux, Perpignan, Poitiers, 
Strasbourg (Saverne), Toulon, Toulouse,
et bientôt : Aurillac.
J'ai noté que 100% de cet argent financera les actions et que 60% de ce don 
ouvre doit à une réduction de l'impôts 2007 ! .

Offrez des " Journées Clowns " aux enfants malades et à nos ainés...
3 façons de nous aider ;
Choisissez la ville où vous souhaitez nous aider et le montant de votre aide
Faites (vous) plaisir utilement en visitant notre BOUTICLOWN
Installez VEOSEARCH sur vos postes et surfez ! A chacune de vos recherches, 
vous collectez de l'argent pour les projets que vous soutenez!

MERCI de votre solidarité !

Les informations qui vous concernent sont destinées à l'association "Clowns 
Z'Hôpitaux ". Nous ne les transmettrons jamais à des tiers.Vous disposez d'un 
droit d'accès, de modification, de rectification  et de suppression des données 
qui vous concernent (art. 34 de la loi "Informatique et Libertés"). Pour 
l'exercer, adressez vous à : Association "Clowns Z'Hôpitaux "
[EMAIL PROTECTED] Tél : 06 27 59 65 18 www.clown-hopital.com

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

[PHP] parsing text for special characters

2007-11-29 Thread Adam Williams
I've got an html form, and I have PHP parse the message variables for 
special characters so when I concatenate all off the message variables 
together, if a person has put in a ' " or other special character, it 
won't break it when it used in mail($to, "MMH Suggestion", "$message", 
"$headers");  below is my snippet of code, but is there a better way to 
parse the text for special characters.  what about if I were to have the 
$message inserted into a mysql field?  how would I need to handle 
special characters that way?


$need_message = $_POST['need_message'];

  function flash_encode($need_message)
  {
 $string = rawurlencode(utf8_encode($need_message));

 $string = str_replace("%C2%96", "-", $need_message);
 $string = str_replace("%C2%91", "%27", $need_message);
 $string = str_replace("%C2%92", "%27", $need_message);
 $string = str_replace("%C2%82", "%27", $need_message);
 $string = str_replace("%C2%93", "%22", $need_message);
 $string = str_replace("%C2%94", "%22", $need_message);
 $string = str_replace("%C2%84", "%22", $need_message);
 $string = str_replace("%C2%8B", "%C2%AB", $need_message);
 $string = str_replace("%C2%9B", "%C2%BB", $need_message);

 return $need_message;
  }

//and then there are $topic_message, $fee_message, etc and they all get 
concatenated with

$message .= needs_message;
$message .= $topics_message;
$message .= $fee message;

//emails the $message
mail($to, "MMH Suggestion", "$message", "$headers");

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



Re: [PHP] parsing text for special characters

2007-11-29 Thread mike
On 11/29/07, Adam Williams <[EMAIL PROTECTED]> wrote:
> I've got an html form, and I have PHP parse the message variables for
> special characters so when I concatenate all off the message variables
> together, if a person has put in a ' " or other special character, it
> won't break it when it used in mail($to, "MMH Suggestion", "$message",
> "$headers");  below is my snippet of code, but is there a better way to
> parse the text for special characters.  what about if I were to have the
> $message inserted into a mysql field?  how would I need to handle
> special characters that way?

htmlentities()
htmlspecialchars()

first i would run $message = filter_input(INPUT_POST, 'message',
FILTER_SANITIZE_STRING);

then probably $message = htmlspecialchars($message);

that should suffice. it depends i suppose. if you need to dump the
html as-is, or you want to encode it first. i don't trust anything
users submit though, so i encode it on output

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



Re: [PHP] Join question

2007-11-29 Thread tedd

At 4:11 PM -0500 11/29/07, Robert Cummings wrote:

Grep? Loop? A single query will suffice. Also, he doesn't mention
wanting to clobber the passwords in table1 when the username does
already exist.

Cheers,
Rob.


Table1 passwords and logins are not populated. I want to take those 
appearing in Table2 and place them in Table1.


Then, I need to take all the entries that are in Table2, but not in 
Table2, and add them to Table1.


I think (could be wrong) it's going to be a two pass operation. 
First, to transfer values to records in the target table (user1) that 
have common username with the source table (user2); Second, to add 
records from the source table (user2) that don't are not found in the 
target table (user1).


user1 Table
username   <-- common to both tables
login <-- needs to be populated
password <-- needs to be populated

user2 Table
username   <-- common to both tables
login  <-- has data
password <-- has data

I thought that --

UPDATE user1 u1, user2 u2
SET u1.login = u2.login, u1.password = u2.password
WHERE u1.username = u2.username

-- would work, but it don't.

Once I can transfer the known data, then I can work on increasing the 
number of entries that are found in user2 but are absent in user1.


Still floundering.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] parsing text for special characters

2007-11-29 Thread Jochem Maas
Adam Williams wrote:
> I've got an html form, and I have PHP parse the message variables for
> special characters so when I concatenate all off the message variables
> together, if a person has put in a ' " or other special character, it

exactly how are ' and " special inside the body of an email message?

> won't break it when it used in mail($to, "MMH Suggestion", "$message",
> "$headers");  below is my snippet of code, but is there a better way to
> parse the text for special characters.  what about if I were to have the

it's not 'parsing' - it's 'escaping', and how you escape depends on the context
in which the string is going to be used.

> $message inserted into a mysql field?  how would I need to handle
> special characters that way?

mysql_real_escape_string()

> 
> $need_message = $_POST['need_message'];
> 
>   function flash_encode($need_message)
>   {
>  $string = rawurlencode(utf8_encode($need_message));
> 
>  $string = str_replace("%C2%96", "-", $need_message);
>  $string = str_replace("%C2%91", "%27", $need_message);
>  $string = str_replace("%C2%92", "%27", $need_message);
>  $string = str_replace("%C2%82", "%27", $need_message);
>  $string = str_replace("%C2%93", "%22", $need_message);
>  $string = str_replace("%C2%94", "%22", $need_message);
>  $string = str_replace("%C2%84", "%22", $need_message);
>  $string = str_replace("%C2%8B", "%C2%AB", $need_message);
>  $string = str_replace("%C2%9B", "%C2%BB", $need_message);
> 
>  return $need_message;
>   }

where is this function used and why would you 'flash encode' a string
destined for the body of an email?

> 
> //and then there are $topic_message, $fee_message, etc and they all get
> concatenated with
> $message .= needs_message;

this line is wrong, unless 'needs_message' is actually a constant.

> $message .= $topics_message;
> $message .= $fee message;

this line is a parse error. have you actually tried to run your code?

> 
> //emails the $message
> mail($to, "MMH Suggestion", "$message", "$headers");

^-- why are these variables inside quotes?

> 

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



[PHP] Batch process PDF files -- reduce color depth and resolution

2007-11-29 Thread Dan Harrington
Hello,

Does anyone know of a good PDF library that works well with PHP (or even
not) that can process multi-page PDF files (I am talking thousands) and
reduce their color depth from color to black and white as well as reduce the
resolution.

I'd like it to run well on Linux.

Thanks
Dan

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



[PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Tommy Baggett
I'm a self-confessed PHP newb (first step towards a cure, right?), so
apologies in advance for what may be a basic question.  I spent an hour
searching for an answer to this and couldn't find one.  

I found one post that said there was a problem with this in 5.0.3, but
it didn't indicate whether the fix was also applied to the PHP4 branch.

I'm using PHP v4.4.7.  I have class B which extends class A.  I'm
overriding a function that is normally called with a variable number of
parameters via call_user_func_array.  How do I call the class A
implementation of the function using call_user_func_array from the class
B implementation?

class A {
  function doSomething($elements, $level) {
...
  }
}

Class B extends A {
  function doSomething($elements, $level) {
...
call_user_func_array(/*class A implementation of doSomething*/,
args); 
  }
}

Thanks in advance for any help!

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



Re: [PHP] Batch process PDF files -- reduce color depth and resolution

2007-11-29 Thread Jochem Maas
Dan Harrington wrote:
> Hello,
> 
> Does anyone know of a good PDF library that works well with PHP (or even
> not) that can process multi-page PDF files (I am talking thousands) and
> reduce their color depth from color to black and white as well as reduce the
> resolution.

yes and when you learn to STWF, STFA and post a question by starting a new 
thread
we might tell you.

> 
> I'd like it to run well on Linux.
> 
> Thanks
> Dan
> 

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



Re: [PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Jochem Maas
Tommy Baggett wrote:
> I'm a self-confessed PHP newb (first step towards a cure, right?), so

if these are your first steps why use php4? php5 has been out for
going on 3 years.

> apologies in advance for what may be a basic question.  I spent an hour
> searching for an answer to this and couldn't find one.  
> 
> I found one post that said there was a problem with this in 5.0.3, but
> it didn't indicate whether the fix was also applied to the PHP4 branch.
> 
> I'm using PHP v4.4.7.  I have class B which extends class A.  I'm
> overriding a function that is normally called with a variable number of
> parameters via call_user_func_array.  How do I call the class A
> implementation of the function using call_user_func_array from the class
> B implementation?
> 
> class A {
>   function doSomething($elements, $level) {
> ...
>   }
> }
> 
> Class B extends A {
>   function doSomething($elements, $level) {
> ...
> call_user_func_array(/*class A implementation of doSomething*/,
> args); 

does this work:?

call_user_func_array(array(parent,'doSomething'),$args);

it's an educated guess, no garantees.

>   }
> }
> 
> Thanks in advance for any help!
> 

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



RE: [PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Tommy Baggett
Thanks for taking the time to reply.

I'm working on a Wordpress theme and extending one of their existing
classes (the Walker class if you're familiar with WP).  Since WP still
supports PHP4, my theme needs to as well.

-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 29, 2007 5:06 PM
To: Tommy Baggett
Cc: php-general@lists.php.net
Subject: Re: [PHP] Calling parent function with call_user_func_array


Tommy Baggett wrote:
> I'm a self-confessed PHP newb (first step towards a cure, right?), so

if these are your first steps why use php4? php5 has been out for going
on 3 years.

> apologies in advance for what may be a basic question.  I spent an 
> hour searching for an answer to this and couldn't find one.
> 
> I found one post that said there was a problem with this in 5.0.3, but

> it didn't indicate whether the fix was also applied to the PHP4 
> branch.
> 
> I'm using PHP v4.4.7.  I have class B which extends class A.  I'm 
> overriding a function that is normally called with a variable number 
> of parameters via call_user_func_array.  How do I call the class A 
> implementation of the function using call_user_func_array from the 
> class B implementation?
> 
> class A {
>   function doSomething($elements, $level) {
> ...
>   }
> }
> 
> Class B extends A {
>   function doSomething($elements, $level) {
> ...
> call_user_func_array(/*class A implementation of doSomething*/, 
> args);

does this work:?

call_user_func_array(array(parent,'doSomething'),$args);

it's an educated guess, no garantees.

>   }
> }
> 
> Thanks in advance for any help!
> 

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



Re: [PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Jochem Maas
Tommy Baggett wrote:
> Thanks for taking the time to reply.
> 
> I'm working on a Wordpress theme and extending one of their existing
> classes (the Walker class if you're familiar with WP).  Since WP still
> supports PHP4, my theme needs to as well.

I know WP, don't like the code too much - but you have a good reason to
be writing for php4 :-)

did my guess work?

...

> does this work:?
> 
>   call_user_func_array(array(parent,'doSomething'),$args);
> 
> it's an educated guess, no garantees.
> 
>>   }
>> }
>>
>> Thanks in advance for any help!
>>
> 

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



Re: [PHP] Join question [solved]

2007-11-29 Thread tedd

Hi gang:

I found why the JOIN didn't work for me in this instance, which was I 
needed to create a third table and JOIN what I needed in that table 
from the other two.


My problem was that I was trying to alter one of the tables in the 
JOIN. While that might be possible it didn't appear so in my current 
problem.


Thanks for letting me bounce ideas off you peoples.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Tommy Baggett

On Nov 29, 2007, at 5:30 PM, Jochem Maas wrote:


does this work:?

call_user_func_array(array(parent,'doSomething'),$args);




It doesn't work with PHP 4.  I was going to try PHP5 on my  
development machine but I will need to do some configuration editing  
first.


Here's the exact code I tried:

class Walker_NavBar extends Walker {
...

function walk($elements, $to_depth) {
$args = func_get_args();

...

// call base class implementation
return call_user_func_array(array(parent,'walk'),$args);
}
...



Re: [PHP] Dynamic Display of Images Stored in DB

2007-11-29 Thread Chris


Hell, I'm all ok with this method... but does (different) webhotells take into 
account the amount used with cache/temp files.
If so, some check should be used, and if not. Cache it all!, and remove the 
timelimit, some check for the change of image of course, but that all depends 
if you acctually change images from time to time..


If it's under your user account then there's no way for them to know 
which parts of your website are cache/temp folders and which aren't. So 
yes, caches & temp files/folders will be included in your disk quota.


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Calling parent function with call_user_func_array

2007-11-29 Thread Nathan Nobbe
On Nov 29, 2007 7:22 PM, Tommy Baggett <[EMAIL PROTECTED]> wrote:

> Here's the exact code I tried:
>
> class Walker_NavBar extends Walker {
> ...
>
>function walk($elements, $to_depth) {
>$args = func_get_args();
>
> ...
>
>// call base class implementation
>return call_user_func_array(array(parent,'walk'),$args);
>}
> ...


wow; i was just looking at the wordpress source;  not the prettiest code ive
ever seen..
anyway; in what context do you intend to use the subclass?  why dont you
just create a
proxy instead?
eg. (php4)

class WalkerProxy {
var $walkerInstance = null;

/**
 * constructor
 *   accept an existing walker instance or create one from scratch
 */
function WalkerProxy($existingWalker=null) {
if(!is_null($existingWalker) && is_a($existingWalker, 'Walker') {
$this->walkerInstance = $existingWalker;
} else {
$this->walkerInstance = new Walker();
}
}

/**
 * walk
 *do custom WalkerProxy stuff then invoke the underlying Walker's
walk() method
 */
function walk($elements, $to_depth) {
  do something custom here
return $this->walkerInstance($elements, $to_depth);
}

   /// .
}

-nathan


RE: [PHP] WSDL Question

2007-11-29 Thread Shanon Swafford

I build an array of the list.  Then nuSOAP helps when converting it to XML
but PHP5 can probably do the same thing.

The following builds an array of line_items to put on an order.  Then
inserts that array into another array containing more order data:

for ($i = 1; $i <= $num_items; $i++) {
   $new_order_item_list[$i] = array(
  'line_number' => $_POST[$myline],
  'item_name'   => $_POST[$myprod],
  'item_id' => $line_item[0]
   );
}

$new_order = array(
   'customer_number'   => addslashes($_POST['customer_number']),
   'customer_password' => addslashes($_POST['customer_password']),
   'customer_email'=> addslashes($_POST['customer_email']),
   'send_me_email' => 'yes',
   'po_number' => addslashes(trim($_POST['po_number'])),
   'itemlist'  => $new_order_item_list
}


This is part of the WSDL it is a client to:


http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
xmlns:tns="urn:OrderService"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
xmlns="http://schemas.xmlsoap.org/wsdl/"; targetNamespace="urn:OrderService">

 http://schemas.xmlsoap.org/soap/encoding/"; />
 http://schemas.xmlsoap.org/wsdl/"; />
 
  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  
 
 
  
   

   
  
 
 
  
   
   
   
   
   
  
 
...
...

Regards


-Original Message-
From: Jonathan Pitcher [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 29, 2007 2:42 PM
To: php-general@lists.php.net
Subject: [PHP] WSDL Question


For the lasts day I have been fighting with PHP, and WSDL calls to a thrid
party provider.

Here is what the call needs to look like:




root

IperiaTestOrg
false


SUBSCRIBER_DEFINED_TRANSFER_NUMBER
6179672983


TIMEZONE
US/CENTRAL






I can generate most of the code in fact I can generate all of it but the
Double service setting.

Here is my relevant PHP code.

$SDT = $portal->get_post('SDT');

$SDT = new SoapVar(array('ns1:type' => 'SUBSCRIBER_DEFINED_TRANSFER_ON',
'ns1:value' => $SDT), SOAP_ENC_OBJECT);

$setting_info = array(array('ns1:serviceSetting' => $SDT));

// Getting Iperia Soap Object ...

$soap_iperia = $portal->load_special_object('soap_iperia');


$find_account_obj->accountIdentifier = new SoapVar(array('ns1:account' =>
'root'), SOAP_ENC_OBJECT);


$find_account_obj->orgID = new SoapVar('IperiaTestOrg', XSD_STRING);

$find_account_obj->suspended = new SoapVar(0, XSD_BOOLEAN);

$find_account_obj->serviceSettingCollection = new SoapVar($setting_info,
SOAP_ENC_OBJECT);

$results = $soap_iperia->modifyOrganization($find_account_obj);

That generates the following xml.




root

IperiaTestOrg
false


SUBSCRIBER_DEFINED_TRANSFER_NUMBER
6179672983





The question I have is how do I add in the extra:



TIMEZONE
US/CENTRAL


I have tried a couple ways with no success ...

Any tips would be greatly appreciated.

Jonathan Pitcher

-- 
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] Join question

2007-11-29 Thread Crayon Shin Chan
On Friday 30 November 2007, Robert Cummings wrote:

> That's an amusing statement. I took a peek back in time and noticed
> that in the past 5 months you've only made two on-topic useful posts to
> the PHP General list-- and they were both for the same thread.

If you have that much free time on your hands, should you not be looking 
for my off-topic posts so you can prove a point?

Or are you saying that one needs to make a lot of on-topic posts to build 
up credit in order to be able to make off-topic posts?

-- 
Crayon

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



[PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
Hi all,

Is it possible to rewind a foreach loop? eg:


$numbers = array(0,1,2,3,4,5,6,7,8,9,10);

foreach ($numbers as $index => $value)
{
if ($value == 5)
{
prev($numbers);
}
echo "Value: $value" . PHP_EOL;
}

The above doesn't seem to work. In one of my scenarios, when I encounter and 
error in a foreach loop, I need the ability to rewind the array pointer by 
one. How can I achieve this?

regards,
Jeffery
-- 
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia
web: http://www.ivt.com.au
phone: +61 3 9723 9399
fax: +61 3 9723 4899

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



Re: [PHP] Join question

2007-11-29 Thread Robert Cummings
On Fri, 2007-11-30 at 10:21 +0800, Crayon Shin Chan wrote:
> On Friday 30 November 2007, tedd wrote:
> > I'm trying to understand joins,
> 
> Ask on a database related list.

That's an amusing statement. I took a peek back in time and noticed that
in the past 5 months you've only made two on-topic useful posts to the
PHP General list-- and they were both for the same thread.

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] Join question [solved]

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 18:43 -0500, tedd wrote:
> Hi gang:
> 
> I found why the JOIN didn't work for me in this instance, which was I 
> needed to create a third table and JOIN what I needed in that table 
> from the other two.
> 
> My problem was that I was trying to alter one of the tables in the 
> JOIN. While that might be possible it didn't appear so in my current 
> problem.

Out of curiosity, what SQL server (and version) are you using? I
currently have MySQL 5.0.33 on my dev box and I had no problem with the
query I gave you. Perhaps it's a version issue. There really shouldn't
be a problem updating a table that also occurs in the select query since
the select query should take place before the insert.

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] Join question [solved]

2007-11-29 Thread Chris



Out of curiosity, what SQL server (and version) are you using? I
currently have MySQL 5.0.33 on my dev box and I had no problem with the
query I gave you. Perhaps it's a version issue. There really shouldn't
be a problem updating a table that also occurs in the select query since
the select query should take place before the insert.


He wasn't doing an insert/select, he was doing an update with two tables 
joined together.




I thought that --

UPDATE user1 u1, user2 u2
SET u1.login = u2.login, u1.password = u2.password
WHERE u1.username = u2.username

-- would work, but it don't.


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
I think the best option for me is to refactorise my code a bit to cater to my 
situation. Thanks all for your help.

Jeffery

On Fri, 30 Nov 2007 02:32:11 pm Jeffery Fernandez wrote:
> On Fri, 30 Nov 2007 02:13:52 pm Chris wrote:
> > Jeffery Fernandez wrote:
> > > On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:
> > >> Jeffery Fernandez wrote:
> > >>> Hi all,
> > >>>
> > >>> Is it possible to rewind a foreach loop? eg:
> > >>>
> > >>>
> > >>> $numbers = array(0,1,2,3,4,5,6,7,8,9,10);
> > >>>
> > >>> foreach ($numbers as $index => $value)
> > >>> {
> > >>> if ($value == 5)
> > >>> {
> > >>> prev($numbers);
> > >>> }
> > >>> echo "Value: $value" . PHP_EOL;
> > >>> }
> > >>>
> > >>> The above doesn't seem to work. In one of my scenarios, when I
> > >>> encounter and error in a foreach loop, I need the ability to rewind
> > >>> the array pointer by one. How can I achieve this?
> > >>
> > >> echo $numbers[$index-1] . PHP_EOL;
> > >
> > > That will only give me the value of the previous index. What I want is
> > > to rewind the array pointer and continue with the loop.
> >
> > and you're going to be in an endless loop then.. because each time it
> > gets rewound, it gets the same key again and rewinds and ...
>
> No, I am only rewinding if there is an error. Then I have the script
> auto-learning from the error, fix a config file and then want to go back to
> the array pointer to re-execute the process.
>
> > You could do it with a for or while loop probably.
>
> Thats what I am looking at now.
>
> > What are you trying to achieve? Maybe there's an alternative.
>
> As mentioned above.
>
> cheers,
> Jeffery
>
> > --
> > Postgresql & php tutorials
> > http://www.designmagick.com/
>
> --
> Internet Vision Technologies
> Level 1, 520 Dorset Road
> Croydon
> Victoria - 3136
> Australia
> web: http://www.ivt.com.au
> phone: +61 3 9723 9399
> fax: +61 3 9723 4899



-- 
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia
web: http://www.ivt.com.au
phone: +61 3 9723 9399
fax: +61 3 9723 4899

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



Re: [PHP] Join question

2007-11-29 Thread Robert Cummings
On Fri, 2007-11-30 at 11:00 +0800, Crayon Shin Chan wrote:
> On Friday 30 November 2007, Robert Cummings wrote:
> 
> > That's an amusing statement. I took a peek back in time and noticed
> > that in the past 5 months you've only made two on-topic useful posts to
> > the PHP General list-- and they were both for the same thread.
> 
> If you have that much free time on your hands, should you not be looking 
> for my off-topic posts so you can prove a point?

Took me 60 seconds. I don't delete my emails.

> Or are you saying that one needs to make a lot of on-topic posts to build 
> up credit in order to be able to make off-topic posts?

No, I'm merely pointing out the hypocrisy.

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] Rewind foreach loop

2007-11-29 Thread Casey

$keys = array_values($array);
for ($i=0; $i wrote:


Jeffery Fernandez wrote:

On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:

Jeffery Fernandez wrote:

Hi all,

Is it possible to rewind a foreach loop? eg:


$numbers = array(0,1,2,3,4,5,6,7,8,9,10);

foreach ($numbers as $index => $value)
{
   if ($value == 5)
   {
   prev($numbers);
   }
   echo "Value: $value" . PHP_EOL;
}

The above doesn't seem to work. In one of my scenarios, when I  
encounter

and error in a foreach loop, I need the ability to rewind the array
pointer by one. How can I achieve this?

echo $numbers[$index-1] . PHP_EOL;
That will only give me the value of the previous index. What I want  
is to rewind the array pointer and continue with the loop.


and you're going to be in an endless loop then.. because each time  
it gets rewound, it gets the same key again and rewinds and ...


You could do it with a for or while loop probably.

What are you trying to achieve? Maybe there's an alternative.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
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] Join question [solved]

2007-11-29 Thread Robert Cummings
On Fri, 2007-11-30 at 14:00 +1100, Chris wrote:
> > Out of curiosity, what SQL server (and version) are you using? I
> > currently have MySQL 5.0.33 on my dev box and I had no problem with the
> > query I gave you. Perhaps it's a version issue. There really shouldn't
> > be a problem updating a table that also occurs in the select query since
> > the select query should take place before the insert.
> 
> He wasn't doing an insert/select, he was doing an update with two tables 
> joined together.

He was doing an update/select and an insert/select. And the query I sent
performed the insert/select without problem on my system. A similar
query would have done the update/select. The fact that the select
portion required a join doesn't change anything.

> 
> 
> I thought that --
> 
> UPDATE user1 u1, user2 u2
> SET u1.login = u2.login, u1.password = u2.password
> WHERE u1.username = u2.username
> 
> -- would work, but it don't.

Wrong query for either of the needs :)

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] Rewind foreach loop

2007-11-29 Thread Steve Edberg

At 2:11 PM +1100 11/30/07, Jeffery Fernandez wrote:

On Fri, 30 Nov 2007 02:01:47 pm Chris <[EMAIL PROTECTED]> wrote:

 Jeffery Fernandez wrote:
 > Hi all,
 >
 > Is it possible to rewind a foreach loop? eg:
 >
 >
 > $numbers = array(0,1,2,3,4,5,6,7,8,9,10);
 >
 > foreach ($numbers as $index => $value)
 > {
 > if ($value == 5)
 > {
 > prev($numbers);
 > }

 > > echo "Value: $value" . PHP_EOL;

 > }
 >
 > The above doesn't seem to work. In one of my scenarios, when I encounter
 > and error in a foreach loop, I need the ability to rewind the array
 > pointer by one. How can I achieve this?

 echo $numbers[$index-1] . PHP_EOL;


That will only give me the value of the previous index. What I want is to
rewind the array pointer and continue with the loop.



I would think that if you rewound the array pointer as above, you'd 
simply end up in an infinite loop, as you'd keep hitting the 
condition that triggered the rewind. So I'm assuming you have some 
other test in there and this is just a stripped down example.


If you're using a one-dimensional array, as opposed to a 
multidimensional and/or associative array, you can do (untested):


$Count = count($numbers);

for ($i=0; $i<$Count; $i++) {
$value = $numbers[$i];
if ($value == 5 && some_other_test()) {
$value = $numbers[--$i];
}
echo "Value: $value" . PHP_EOL;
}

Wouldn't be much more complex to extend to a multidimensional array 
with an integer index. If you were using an associative array with a 
string index, you'd probably have to do something like


$NotJustNumbers = array('a'=>'slurm', 'b'=>'fry', 'c'=>'leela');
$Keys = array_keys($NotJustNumbers);
$Count = count($Keys);

for ($i=0; $i<$Count; $i++) {
$value = $NotJustNumbers[$Keys[$i]];
if ($value == 5 && some_other_test()) {
$value = $NotJustNumbers[$Keys[--$i]];
}
echo "Value: $value" . PHP_EOL;
}


- steve

--
+--- my people are the people of the dessert, ---+
| Steve Edberghttp://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center[EMAIL PROTECTED] |
| Bioinformatics programming/database/sysadmin (530)754-9127 |
+ said t e lawrence, picking up his fork +

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



Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris

Jeffery Fernandez wrote:

Hi all,

Is it possible to rewind a foreach loop? eg:


$numbers = array(0,1,2,3,4,5,6,7,8,9,10);

foreach ($numbers as $index => $value)
{
if ($value == 5)
{
prev($numbers);
}
echo "Value: $value" . PHP_EOL;
}

The above doesn't seem to work. In one of my scenarios, when I encounter and 
error in a foreach loop, I need the ability to rewind the array pointer by 
one. How can I achieve this?


echo $numbers[$index-1] . PHP_EOL;

Of course that assumes that the value you're looking for isn't the first 
element :)


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:
> Jeffery Fernandez wrote:
> > Hi all,
> >
> > Is it possible to rewind a foreach loop? eg:
> >
> >
> > $numbers = array(0,1,2,3,4,5,6,7,8,9,10);
> >
> > foreach ($numbers as $index => $value)
> > {
> > if ($value == 5)
> > {
> > prev($numbers);
> > }
> > echo "Value: $value" . PHP_EOL;
> > }
> >
> > The above doesn't seem to work. In one of my scenarios, when I encounter
> > and error in a foreach loop, I need the ability to rewind the array
> > pointer by one. How can I achieve this?
>
> echo $numbers[$index-1] . PHP_EOL;

That will only give me the value of the previous index. What I want is to 
rewind the array pointer and continue with the loop.

>
> Of course that assumes that the value you're looking for isn't the first
> element :)
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/



-- 
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia
web: http://www.ivt.com.au
phone: +61 3 9723 9399
fax: +61 3 9723 4899

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



Re: [PHP] Join question

2007-11-29 Thread Crayon Shin Chan
On Friday 30 November 2007, tedd wrote:
> I'm trying to understand joins,

Ask on a database related list.

-- 
Crayon

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



Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris

Jeffery Fernandez wrote:

On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:

Jeffery Fernandez wrote:

Hi all,

Is it possible to rewind a foreach loop? eg:


$numbers = array(0,1,2,3,4,5,6,7,8,9,10);

foreach ($numbers as $index => $value)
{
if ($value == 5)
{
prev($numbers);
}
echo "Value: $value" . PHP_EOL;
}

The above doesn't seem to work. In one of my scenarios, when I encounter
and error in a foreach loop, I need the ability to rewind the array
pointer by one. How can I achieve this?

echo $numbers[$index-1] . PHP_EOL;


That will only give me the value of the previous index. What I want is to 
rewind the array pointer and continue with the loop.


and you're going to be in an endless loop then.. because each time it 
gets rewound, it gets the same key again and rewinds and ...


You could do it with a for or while loop probably.

What are you trying to achieve? Maybe there's an alternative.

--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
On Fri, 30 Nov 2007 02:13:52 pm Chris wrote:
> Jeffery Fernandez wrote:
> > On Fri, 30 Nov 2007 02:01:47 pm Chris wrote:
> >> Jeffery Fernandez wrote:
> >>> Hi all,
> >>>
> >>> Is it possible to rewind a foreach loop? eg:
> >>>
> >>>
> >>> $numbers = array(0,1,2,3,4,5,6,7,8,9,10);
> >>>
> >>> foreach ($numbers as $index => $value)
> >>> {
> >>> if ($value == 5)
> >>> {
> >>> prev($numbers);
> >>> }
> >>> echo "Value: $value" . PHP_EOL;
> >>> }
> >>>
> >>> The above doesn't seem to work. In one of my scenarios, when I
> >>> encounter and error in a foreach loop, I need the ability to rewind the
> >>> array pointer by one. How can I achieve this?
> >>
> >> echo $numbers[$index-1] . PHP_EOL;
> >
> > That will only give me the value of the previous index. What I want is to
> > rewind the array pointer and continue with the loop.
>
> and you're going to be in an endless loop then.. because each time it
> gets rewound, it gets the same key again and rewinds and ...

No, I am only rewinding if there is an error. Then I have the script 
auto-learning from the error, fix a config file and then want to go back to 
the array pointer to re-execute the process.

>
> You could do it with a for or while loop probably.
Thats what I am looking at now.

>
> What are you trying to achieve? Maybe there's an alternative.
As mentioned above.

cheers,
Jeffery
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/



-- 
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia
web: http://www.ivt.com.au
phone: +61 3 9723 9399
fax: +61 3 9723 4899

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



Re: [PHP] Join question

2007-11-29 Thread Crayon Shin Chan
On Friday 30 November 2007, Robert Cummings wrote:
> > Or are you saying that one needs to make a lot of on-topic posts to
> > build up credit in order to be able to make off-topic posts?
>
> No, I'm merely pointing out the hypocrisy.

That would only be true if I had been making off-topic posts. But so far 
all you have concluded is that during the last 5 months I have "only made 
two on-topic useful posts".

-- 
Crayon

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



Re: [PHP] Join question

2007-11-29 Thread Robert Cummings
On Fri, 2007-11-30 at 13:49 +0800, Crayon Shin Chan wrote:
> On Friday 30 November 2007, Robert Cummings wrote:
> > > Or are you saying that one needs to make a lot of on-topic posts to
> > > build up credit in order to be able to make off-topic posts?
> >
> > No, I'm merely pointing out the hypocrisy.
> 
> That would only be true if I had been making off-topic posts. But so far 
> all you have concluded is that during the last 5 months I have "only made 
> two on-topic useful posts".

I'm sorry, allow me to rephrase... in the past 5 months you've made 2
on-topic useful posts, with the rest either being on-topic for an
off-topic thread, or completely off-topic. I see no point in saying
more, I've made my point.

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] Dynamic Display of Images Stored in DB

2007-11-29 Thread Børge Holen
On Friday 30 November 2007 00:39:39 Chris wrote:
> > Hell, I'm all ok with this method... but does (different) webhotells take
> > into account the amount used with cache/temp files.
> > If so, some check should be used, and if not. Cache it all!, and remove
> > the timelimit, some check for the change of image of course, but that all
> > depends if you acctually change images from time to time..
>
> If it's under your user account then there's no way for them to know
> which parts of your website are cache/temp folders and which aren't. So
> yes, caches & temp files/folders will be included in your disk quota.

I mean't system wide, like the php temp files, or /tmp. 

-- 
---
Børge Holen
http://www.arivene.net

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