Re: [PHP] Object to array conversion oddity

2006-09-26 Thread Marcus Bointon

On 26 Sep 2006, at 23:52, Richard Lynch wrote:


You start using that PHP5 private/protected stuff, and it just doesn't
make sense to coerce it to an array, imho.


I'm quite aware of that, and in this case I'm using it in a one-off  
string-and-glue fix for a specific problem until I fix it properly.  
The original question wasn't whether it was a good idea or not, but  
that it didn't act as the docs said it did. In the mean time, you  
might like to know that this behaviour IS apparently considered  
correct and a patch to documentation has been committed.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon

On 24 Sep 2006, at 01:05, Robert Cummings wrote:

Blah, blah, blah. The documentation is probably out of date and  
applied
to PHP4. Feel free to get off your arse and volunteer if you don't  
like

it :) You don't get have your cake and eat it *PTHTHTHTHTTHTHTH*


How exactly am I not helping by pointing out there's a problem in the  
first place? It's a lot more constructive than being rude.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon

On 24 Sep 2006, at 01:09, Robert Cummings wrote:


It's broken, it doesn't preserve references.


?php
class A {
private $A;
}
class B extends A {
private $A;
public $B;
protected $c;}
$a = new B;
$b = new B;
$b-B = $a;
var_dump(object2array($b));
?

array(3) {
  [A]=
  NULL
  [B]=
  object(B)#1 (4) {
[A:private]=
NULL
[B]=
NULL
[c:protected]=
NULL
[A:private]=
NULL
  }
  [c]=
  NULL
}

Reference preserved. It's not like I care about PHP4, nor am I doing  
a deep conversion.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon

On 24 Sep 2006, at 22:07, Ray Hauge wrote:


Maybe you missed it, but he did submit a bug report:

http://bugs.php.net/?id=38935

He just wanted to see if other people had run into a similar  
situation before
submitting the bug... from my understanding.  I don't want to put  
words in

Marcus' mouth


Yup (and thanks), that was exactly my intention. Initially I wasn't  
sure that I was not doing something wrong, or seeing interference  
from XDebug etc. It's hard enough getting a PHP bug report accepted  
at all, so I try to make sure that it's very, very clear. I'm quite  
used to getting 'bogusbotted' by now - you seem to have to fight for  
every bug, in code or documentation. I appreciate that the  
maintainers have to deal with a lot of crap, and I make an effort not  
to waste their time (e.g. by reading docs, searching archives,  
posting on -users, as they suggest), but occasionally they just don't  
read the report - in this case I was referred to the documentation,  
which agrees 100% with my complaint!


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



[PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon

A simple class like this:

class Myclass() {
public $field1 = '';
private $field2 = '';
public function __sleep() {
  return array('field1', 'field2');
}
}
$myclass = new Myclass;

If I var_dump this, I get:

object(Myclass)#6 (2) {
  [field1]=
  string(0) 
  [field2:private]=
  string(0) 
}

If I coerce this to an array:

$arr = (array)$myclass;

the properties change names in a most unhelpful way:

array(2) {
  [field1]=
  string(0) 
  [Myclassfield2]=
  string(0) 
}

The docs (http://www.php.net/manual/en/language.types.array.php) say:

If you convert an object to an array, you get the properties (member  
variables) of that object as the array's elements. The keys are the  
member variable names.


It seems that's not quite true.

How can I stop it doing this? Looks a bit buggy to me.

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon

On 23 Sep 2006, at 15:51, Ray Hauge wrote:


To me it looks like they append the name of the class to any private
variables.  I would guess that it does this to make sure you know  
what you're
doing and using the private variable like that.  I'm  just guessing  
at that

point though.


Well, I realised that, but it's not very helpful as there's no  
separator between class name and variable name it's impossible to  
separate it correctly - if I had happened to have a property called  
'myclassfield1', I would not be able to tell if the real property  
name was 'myclassfield1' or a private property called 'field1'. If it  
is going to stray from the documented behaviour, It would be far more  
useful to retain the names that the var_dump on the object uses -  
'field1:private'. That's safe as : is not a value char in a variable  
name, but it's fine as an array index.


Try a test with multiple public and multiple private variables.  If  
the format

of the array keys stays the same, then you should have your answer.


In my real code I do have multiple fields all exhibiting this  
behaviour. I'll report it.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon

Here's a more accurate example:

?php
class Myclass {
public $field1 = '';
private $field2 = '';
protected $field3 = '';
}

$myclass = new Myclass;

var_dump($myclass);
var_dump((array)$myclass);
?

This produces:

object(Myclass)#1 (3) {
  [field1]=
  string(0) 
  [field2:private]=
  string(0) 
  [field3:protected]=
  string(0) 
}
array(3) {
  [field1]=
  string(0) 
  [Myclassfield2]=
  string(0) 
  [*field3]=
  string(0) 
}

So it seems protected fields behave differently too.

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon

On 23 Sep 2006, at 16:37, Ray Hauge wrote:


Could you do something like this?

$private = Myclass
$protected = *;


No, because if I have a property called 'Myclassfield1', after  
casting to an array I can't tell if it's private property called  
'field1' or a public property called 'Myclassfield1'.


I think it's just plain wrong. Arrays should not try to be objects.  
You can find out protection level of a property via introspection of  
the object that you have in hand. In the vast majority of cases,  
you'll want it to act just like the docs say it does, and if you  
don't, you should probably be using the object itself anyway.


Bug report is here: http://bugs.php.net/?id=38935

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon

On 23 Sep 2006, at 16:46, Robert Cummings wrote:


And the likelihood of you having a property called Myclassfield1 is?


Sure, but don't you think that coding should at least try to be  
driven by logic rather than luck? I'm also not denying that it's not  
too hard to work around (with a function not dissimilar to what you  
suggested), but I'd really prefer it if it just did what it says on  
the tin. By its very nature, casting from object to array indicates  
that you no longer want the constraints of property protection, which  
an array can't preserve anyway, and it's not as if there are not  
intentional, documented methods of obtaining this information.



It sounds like they've helped out by giving more data than was
necessary.


...and in doing so defaults to breaking code that expects it to  
behave like the documentation says it does? I don't think I'd  
classify that as helping out. Bear in mind that my code broke in  
exactly this way. If you want to find out what the access level of a  
property is, I doubt your first thought would be to convert it to an  
array - and I bet you didn't know that this info was even there  
because it's not documented, thus helping nobody. This is what  
introspection is for. I don't have a problem with being provided with  
extra information, just as long as it doesn't interfere with correct  
operation, which is what it currently does. It could provide the  
extra info in a marginally less destructive way, for example by  
adding 'private' and 'protected' array properties containing field  
names for each access level to the resulting array. OTOH, that would  
break what you'd expect count() to deliver after the conversion. I  
really think it should just do what's it's meant to, and no more.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon


On 23 Sep 2006, at 18:54, Jon Anderson wrote:


If you just want an array of properties, add this to your class...


That's exactly the kind of thing I was on about. Since reflection  
gives access to all this information, why bother trying to squeeze  
the same info into an array-shaped container that just can't hold all  
the same info without corrupting it? I can see that there might be  
some reason for converting the object with additional information in  
some circumstances (much like serialization to strings does), but  
here we're only talking about casting, which should be a 'best-fit'  
data matter. The behaviour we've got would be better served with a  
function like toArrayPreservingClassInfo() rather than the default  
casting behaviour.


Since reporting the bug (which was immediately marked as bogus; go  
figure), I've had something else brought to my attention: The  
resulting array keys are not what they seem! Their actual structure is:


NULLclassnameNULLpropertyname

So, here we have undocumented behaviour justified by yet more  
undocumented behaviour! How behaviour so wildly different to what's  
documented is not considered a bug I don't know. At least this format  
can be dismantled reliably, rather than trying to string-match class  
names. I think trying to preserve this information (as you said) is  
entirely pointless - it's not as if you can cast back from an array  
to an object, and I can't think of any circumstances in which it is  
preferable to using reflection (unless it's a relic from PHP4?).  
What's next - appending a creation time to integers when they're cast  
into strings?


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
I've written a function that does a conversion that matches the docs,  
based on the other info I've mentioned:


/**
* Clean up the name munging that PHP applies while casting from  
object to array
* The resulting array looks like what the documentation says that  
(array)$object delivers, but actually doesn't

* @param object $object The object to convert
* @return array
*/
function object2array($object) {
$class = get_class($object);
$array = (array)$object;
$propArray = array();
$matches = array();
foreach ($array as $key = $value) {
		if (preg_match('/^\0(([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\0 
([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$/', $key, $matches)) {

//It's a private property
if ($matches[1] == $class) { //Ignore private props of 
superclasses
$propArray[$matches[2]] = $value;
}
		} elseif (preg_match('/^\0(\*)\0([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f- 
\xff]*)$/', $key, $matches)) {

//It's a protected property
$propArray[$matches[2]] = $value;
} else {
//It's a public property
$propArray[$key] = $value;
}
}
return $propArray;
}

Works nicely for me.

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Recommendations for PHP debuggers?

2006-08-21 Thread Marcus Bointon

On 21 Aug 2006, at 04:55, Dave M G wrote:


So I'm looking around for other debugging options.


One oft-overlooked option: xdebug.org. It enhances PHP's built-in  
debugging features enormously, adds profiling, trace and coverage  
logging, remote debugging too. The improved readability of stack  
traces alone makes it worthwhile IMHO.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/

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



Re: [PHP] Re: loop in horizontal direction (php-html)

2006-08-10 Thread Marcus Bointon

On 10 Aug 2006, at 16:39, Al wrote:


tds don't need to be terminated with /tds


That is, assuming you don't want your pages to validate. As closing  
your tags is so trivially easy, it's really not worth not doing! I  
recently encountered a site that contained 3500 unclosed font tags on  
a single page; This is a very good way of making a browser go very  
slowly and eat lots of memory.


Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
[EMAIL PROTECTED] | http://www.synchromedia.co.uk/



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



[PHP] $_SERVER['REMOTE_ADDR'] arriving in IPv6

2006-05-18 Thread Marcus Bointon
I'm running PHP 5.1.4 on OS X. When I look at $_SERVER 
['REMOTE_ADDR'], it seems to contain an ipv6 address rather than an  
ipv4 one (at present it's giving me 'fe80::1' instead of the usual  
dotted quad), and that confuses the hell out of things like MySQL's  
INET_ATON() function. I have ipv6 networking disabled in my network  
control panel, and my PHP is configured with --disable-ipv6. How can  
I force it to return only ipv4 addresses? Is there an ini setting  
somewhere?


Thanks,

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] $_SERVER['REMOTE_ADDR'] arriving in IPv6

2006-05-18 Thread Marcus Bointon

On 18 May 2006, at 21:11, Stut wrote:

The value in that variable is coming from the web server not PHP. I  
suggest you change the web server configuration so it's listening  
on specific v4 IPs only rather than all IPs. See the docs for your  
web server for details on how to do that.


Yup, that was it, thanks. It appears that Apache 2 on OS X listens on  
IPv6 by default. To force it to listen on IPv4 only, change the  
default listen directive in httpd.conf to look like this:


Listen 0.0.0.0:80

Here's the reference: http://httpd.apache.org/docs/2.0/bind.html

Worked a treat for me.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Beware of OS X PHP security update...

2006-03-03 Thread Marcus Bointon
The OS X security update issued yesterday includes a PHP 'fix', by  
which they mean that it installs PHP 4.4.1. If you have installed PHP  
5 from elsewhere, it will get trashed along with your PEAR setup.  
PEAR is now completely confused or me and just crashes when I try to  
do anything.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Compiling PHP with freetype2 on MacOS X

2006-02-24 Thread Marcus Bointon
Recently I've not been able to compile PHP 5.1.2 on OS X 10.4 with gd  
and freetype2 support. I've found various threads on this, but none  
of the proposed fixes work. My configure line includes:


--with-gd=/sw --with-freetype-dir=/sw/lib/freetype2 --with-t1lib=/sw

It doesn't report any problems when configuring:

...
checking for GD support... yes
checking for the location of libjpeg... /sw
checking for the location of libpng... /sw
checking for the location of libXpm... no
checking for FreeType 1.x support... /sw
checking for FreeType 2... /sw/lib/freetype2
checking for T1lib support... /sw
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for jpeg_read_header in -ljpeg... (cached) yes
checking for png_write_image in -lpng... (cached) yes
If configure fails try --with-xpm-dir=DIR
checking for FreeType 1 support... no - FreeType 2.x is to be used  
instead

checking for T1_StrError in -lt1... (cached) yes
checking for gdImageString16 in -lgd... (cached) yes
checking for gdImagePaletteCopy in -lgd... (cached) yes
checking for gdImageCreateFromPng in -lgd... (cached) yes
checking for gdImageCreateFromGif in -lgd... (cached) yes
checking for gdImageGif in -lgd... (cached) yes
checking for gdImageWBMP in -lgd... (cached) yes
checking for gdImageCreateFromJpeg in -lgd... (cached) yes
checking for gdImageCreateFromXpm in -lgd... (cached) yes
checking for gdImageCreateFromGd2 in -lgd... (cached) yes
checking for gdImageCreateTrueColor in -lgd... (cached) yes
checking for gdImageSetTile in -lgd... (cached) yes
checking for gdImageEllipse in -lgd... no
checking for gdImageSetBrush in -lgd... (cached) yes
checking for gdImageStringTTF in -lgd... (cached) yes
checking for gdImageStringFT in -lgd... (cached) yes
checking for gdImageStringFTEx in -lgd... (cached) yes
checking for gdImageColorClosestHWB in -lgd... (cached) yes
checking for gdImageColorResolve in -lgd... (cached) yes
checking for gdImageGifCtx in -lgd... (cached) yes
checking for gdCacheCreate in -lgd... (cached) yes
checking for gdFontCacheShutdown in -lgd... (cached) yes
checking for gdFreeFontCache in -lgd... (cached) yes
checking for gdNewDynamicCtxEx in -lgd... (cached) yes
checking for gdImageCreate in -lgd... (cached) yes

but when I make:

/Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function 'zm_info_gd':
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: 'FREETYPE_MAJOR'  
undeclared (first use in this function)
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: (Each undeclared  
identifier is reported only once
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: for each function  
it appears in.)
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: 'FREETYPE_MINOR'  
undeclared (first use in this function)

/Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function 'php_imagechar':
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:2817: warning: pointer  
targets in passing argument 1 of 'strlen' differ in signedness
/Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function  
'php_imagettftext_common':
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:3197: warning: pointer  
targets in passing argument 4 of 'gdImageStringFTEx' differ in  
signedness
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:3197: warning: pointer  
targets in passing argument 9 of 'gdImageStringFTEx' differ in  
signedness
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:3203: warning: pointer  
targets in passing argument 4 of 'gdImageStringFT' differ in signedness
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:3203: warning: pointer  
targets in passing argument 9 of 'gdImageStringFT' differ in signedness

make: *** [ext/gd/gd.lo] Error 1

Those undefined constants sound like it's missing a header file  
somewhere.


I've also tried using the built-in freetype2 lib using --with- 
freetype-dir=/usr/X11R6 but that gives me the same error. I've also  
tried using the bundled gd lib, again I get the same error. I've cut  
my configure line down to just the options for the environment, gd  
and freetype. I've looked in /sw/lib/freetype2/include/freetype2/ 
freetype/freetype.h and the missing constants are correctly defined  
in there, and also in /usr/X11R6/include/freetype2/freetype/ 
freetype.h Those files should be found using the paths I gave in  
configure.


Anyone got any idea how I can fix this?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Recompile PHP on pre-installed system

2006-02-07 Thread Marcus Bointon

On 7 Feb 2006, at 11:13, Jochem Maas wrote:

in theory your done, in practice something might bite you in the  
ass ...
oh and then there is the issue of making sure that the redhat  
package manager really
won't overwrite your handbuilt php install (cannot for the life of  
me remember what you have

to do to make redhat ignore the php install).


This might be of help: http://www.ae.iitm.ac.in/pipermail/ilugc/2005- 
August/020152.html


You can edit those srpms to include whatever configure line switches  
you need.


I run RHEL4, and my own compile of PHP, set up outside of rpm. You  
only need to worry about rpm getting confused if you use it to  
install any packages that are dependent on php, e.g. squirrelmail.  
Essentially either do ALL of your PHP setup and install through rpm  
or none of it. I'm quite happy handling PHP myself, and conflicts are  
rare as php is rarely a dependency for apps installed through rpm.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] mail() and Return-Path header

2006-02-06 Thread Marcus Bointon

On 2 Feb 2006, at 13:00, Søren Schimkat wrote:

I'm using the mail function for sending mail, and I would like to  
specify the
Return-Path header, but it would seem that PHP or Apache is  
modyfying the

header.


Strictly speaking, you should not set a return-path header at all.  
You should set a 'sender' header, and the return-path header will be  
generated for you by your MTA. The reason for this is that a message  
may gain multiple return-path headers on its journey so that its full  
path can be traced backwards to the source. The common exception to  
this is if you're on Windows and don't have a local MTA (or on any  
platform and have PHPMailer's IsSMTP set), and your script is sending  
directly via SMTP and thus IS the MTA.


If you want to do proper bounce handling, you should also look into  
VERP addressing, as it's the only way to guarantee that you get  
tracable bounces - MS Exchange server sometimes bounces messages with  
no indication of the address the original message was sent to!


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Class constructor

2006-02-01 Thread Marcus Bointon


On 31 Jan 2006, at 13:52, David Grant wrote:


Drop __construct, PHP5 will call Test() anyway.

From http://uk.php.net/manual/en/language.oop5.decon.php:

For backwards compatibility, if PHP 5 cannot find a __construct()
function for a given class, it will search for the old-style  
constructor

function, by the name of the class.


Sure, if you're planning on writing 'backwards' code for ever more...  
For maximum efficiency in PHP5, do it this way around:


class test{
function Test(){
$this-__construct()
//This will be called in PHP4
}
function __construct(){
//This will be called in PHP5
}
}

Why penalise the platform you're intending to run it on?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Wysiwyg editors?

2006-02-01 Thread Marcus Bointon

On 1 Feb 2006, at 07:45, William Stokes wrote:


I once tested htmlarea (http://www.htmlarea.com/) and I think thats


I'd recommend fckeditor and tinymce over htmlarea. Both seem to have  
much more active development, not least that they're both trying to  
get it working in Safari. fckeditor is working great for me from PHP.


http://www.fckeditor.net/
http://tinymce.moxiecode.com/

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] HTML rendering extension?

2005-12-21 Thread Marcus Bointon
Has anyone seen such a thing? I'm looking to be able to generate web  
page previews dynamically and automatically, so I need to render the  
page on the server. The most efficient way would be if there was a  
PHP HTML rendering extension - gecko or KHTML perhaps. HTML2PDF  
doesn't go nearly far enough. Alternatively something like a CLI  
option to firefox to run without X (i.e. no visible windows) and  
output to a file instead of a display device. The options here don't  
indicate that it can do that:


http://kb.mozillazine.org/Command_line_arguments

Any other ideas?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] HTML rendering extension?

2005-12-21 Thread Marcus Bointon

On 21 Dec 2005, at 21:18, M wrote:


http://marginalhacks.com/Hacks/html2jpg/


That's the kind of marginal hack I was hoping to avoid ;^) However,  
it did lead me to http://khtml2png.sourceforge.net/ which seems far  
more like it. Now I just have to persuade it to compile.


Thanks.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] HTML rendering extension?

2005-12-21 Thread Marcus Bointon

On 21 Dec 2005, at 18:17, Richard Lynch wrote:


At least I *think* it was called webthumb...

Maybe from the GD folks???

It's out there somewhere, and I was going to look into it, but...

You'd feed it a URL and it gives you an image.  You need X installed,
so it can run X in the background and render it.


It is indeed called webthumb: http://www.boutell.com/webthumb/

After installing firefox on my server, tweaking webthumb to use  
firefox instead of Mozilla, a bit of messing with xauth settings, and  
I've got it working! It seems like a more polished alternative to  
html2jpg. It uses Xvfb for a local display so you don't need a real  
one, and it doesn't interfere with remote X sessions, though firefox  
complains if you try to run it on both X displays at once. Now I just  
need to go find a borderless chrome package for ff...


khtml2jpg is definitely a more advanced solution as it contains its  
own browser and is thus not limited by screen size - you could grab a  
page 10,000 pixels tall if you wanted to - and it can monitor browser  
state e.g. so it can know when all images are loaded instead of just  
waiting for a bit. Flipside - it's not working for me...


Thanks very much for the tip, very glad to have finally found a  
solution.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] mod_rewrite and include paths

2005-11-21 Thread Marcus Bointon
I found the source of my mod_rewrite problems. I was doing everything  
right to start with - The odd behaviour was due to a PHP bug (http:// 
bugs.php.net/bug.php?id=35059) that's fixed in 4.4.2-dev and 5.1.0RC7- 
dev (I'd assume 5.0.x as well). Recompiling with a new checkout works  
fine.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] APC caching keys.

2005-11-21 Thread Marcus Bointon

On 19 Nov 2005, at 04:07, Curt Zirzow wrote:


If you are using mysql i would use the SQL_CACHE flag, it will
eliminate the need for you to manage the cache.


You don't necessarily need to us the SQL_CACHE flag in queries - you  
can just turn on the query cache globally using query_cache_type=1 in  
your my.cnf. Otherwise I quite agree - and MySQL has the huge  
advantage that it will work very nicely across multi-server deployments:


http://dev.mysql.com/doc/refman/5.0/en/query-cache.html


The last version of php5.1 i have installed APC on is a cvs
snapshot of around Feb 4 2005 11:49:05. Nothing special was needed.


The current 3.0.8 release of APC is broken in PHP 5.1.0-dev if you  
ever use __autoload. It will be fixed in 3.0.9 (and is fixed in CVS),  
though Rasmus implied that 3.0.9 is waiting until 5.1 release.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] php5 call by refference

2005-11-21 Thread Marcus Bointon

On 21 Nov 2005, at 09:26, Georgi Ivanov wrote:


AFAIK, in PHP5 one can't call function with function parameters .
The error is that you only can pass variables by reference.
foo(strlen('aaa'),strlen(''));


You can call functions like that without problems UNLESS the function  
is expecting values by reference, i.e. results are passed back  
through the parameters. If you supply a function result, then you may  
as well not be calling the function as you'll never be able to get a  
result back from it, hence the error message. e.g.


function foo($a, $b) {
$a = $a.$b;
}

If you call this as you asked, where would the result go?


Is there some sort of workaround ?


As was suggested, put your values in variables before calling the  
function, though the code example you posted suggests you're trying  
to do something odd.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] using ($test)?$true:$false in a string

2005-11-21 Thread Marcus Bointon


On 18 Nov 2005, at 20:13, Dylan wrote:


$var = first part of string .(($a==$b)?$c:$d). rest of string;

and I feel it would be more elegant to be able to do something like:

$var =first part of string {(($a==$b)?$c:$d)} rest of string;


Strange as it may seem, you'll probably find that this is the fastest  
method:


'first part of string '.(($a==$b)?$c:$d).' rest of string'

I benchmarked this a while ago and was surprised to find that  
multiple concats with single quotes are significantly faster than  
interpolation.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] APC caching keys.

2005-11-21 Thread Marcus Bointon

On 21 Nov 2005, at 10:54, Jochem Maas wrote:

having said that I don't use __autoload() - I did but it was just a  
PITA -


I thought it was a good idea for a while... One major irritation with  
it is that with standard error reporting you can't tell where a  
missing class can't be found from (it is reported as having come from  
your __autoload function). You need a stack trace to figure out where  
the original problem occurred - xdebug works a treat (but it won't  
mix with APC).


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: PHP 4.4.1 on Apache 2.0.x issue

2005-11-21 Thread Marcus Bointon

On 20 Nov 2005, at 15:14, Geert Booster wrote:


  PHP 4.4.0, since PHP developers seem not interested in
  fixing the bug with apache2 and mod_rewrite


I think you might find this bug report of interest, especially since  
it's been fixed: http://bugs.php.net/bug.php?id=35059 It's certainly  
fixed things for me.


Derick's 4.4.2RC1 release note a couple of days ago:

On 18 Nov 2005, at 11:58, Derick Rethans wrote:

I packed PHP 4.4.2RC1 today, which you can find here:
http://downloads.php.net/derick/ . Windows binaries will follow  
shortly.


Please test it carefully, and report any bugs in the bug system, but
only if you have a short reproducable test case.

If everything goes well, we can release it next tuesday. Especially  
test

issues with mod_rewrite and Apache 2 please!


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Sorting users geographically...

2005-11-21 Thread Marcus Bointon


On 21 Nov 2005, at 14:14, Tony Di Croce wrote:

Does anyone know of any commercial or free implementations of this?  
Is it

primarily a database problem or is their some way (computationally) to
compute the probable proximity of two zip codes?


All the suggested packages could be all you need, but also note that  
MySQL 5 has built-in GIS features which may make searches like these  
way more efficient should they use them:


http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions-in-mysql.html
http://dev.mysql.com/doc/refman/5.0/en/functions-that-test-spatial- 
relationships-between-geometries.html


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] using ($test)?$true:$false in a string

2005-11-21 Thread Marcus Bointon

On 21 Nov 2005, at 15:43, Jochem Maas wrote:


using sprintf() is
such a simple case may be excessive BUT I was merely introducing  
the OP to

something new (possibly) - anyone asking such 'simple' questions is
not at a stage that this kind of efficiency is an issue (i.e. give
them 'whats possible' before telling them 'whats best')


sprintf is also a good example of a different way of thinking about  
string interpolation, and what's more it's remarkably close to the  
whole concept of using prepared statements in SQL, a measure that can  
gain you both speed and security, plus it's supported very nicely in  
PDO in PHP 5.1. A tangent I know, but a useful one nonetheless. Hey,  
and I remember when print using was considered a 'power user'  
feature in BASIC in 1981!


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] forking off in php

2005-11-21 Thread Marcus Bointon

On 21 Nov 2005, at 17:39, matt VanDeWalle wrote:


I have what may seem like a small problem but its not obvious to me.
I have a script that I forked and that part works fine, it forks,  
tells me the pid like I wanted, and keeps running.  Well, the  
problem that was not apparent to me until about 3 days ago when I  
was wondering why the script(my php chat server) was crashing at  
seeminly random times.  I finally  figured out that when I logged  
out of my shell in linux, the talker would go down as well.   
Obviously I don't want that but what do I need to add to the line  
when i start the script


Example1 on the php docs page is what you need:

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

The important thing is the call to posix_setsid(), which detaches  
your forked process from your terminal process. Works great for me -  
I've had PHP daemons running for over 9 months without a break.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] forking off in php

2005-11-21 Thread Marcus Bointon

On 21 Nov 2005, at 17:47, Jay Blanchard wrote:


It would have been nice to see your command line. Add '' i.e.


You don't need to do that - the forking script will start, spawn a  
child process then exit, so adding  will do nothing. Having said  
that, you could achieve something similar by not forking and using  
nohup (look it up with man) with , however, that will mean it runs  
as you, whereas a forked process can easily switch users and drop  
privileges for increased security.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Is echo tag reasonably portable?

2005-11-18 Thread Marcus Bointon

On 15 Nov 2005, at 19:53, Robin Vickery wrote:


I doubt very much if they will be disabled. They are perfectly valid
SGML processing instructions.


Firstly, I didn't actually suggest they were disabled. I suggested
that they should be off by default.


Late to the party I know, but I think something has been missed here.  
Here's an excerpt from php.ini-recommended in a fresh download of PHP:


; Allow the ? tag.  Otherwise, only ?php and script tags are  
recognized.
; NOTE: Using short tags should be avoided when developing  
applications or

; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off

Given most ISPs habit of leaving everything at defaults, I'd say this  
pretty much puts paid to using short tags.


Admittedly it is on in php.ini-dist, but that's not recommended is  
it ;^)


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Set Timezone to localtime in php.ini

2005-11-18 Thread Marcus Bointon

On 16 Nov 2005, at 04:49, The Doctor wrote:


IS their a way to set the time to localtime instead of GMT in
the ini file?

Some users are complaining that they are seeing GMT, which this server
is set to.


If you use PHP 5.1, yes: http://www.php.net/manual/en/ref.datetime.php

Note the new date.timezone ini setting.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Newbie to PHP5

2005-11-15 Thread Marcus Bointon

On 15 Nov 2005, at 10:06, Danny wrote:

 I´m familiar with PHP syntax, but I´ve been reading some sample  
scripts, in

PHP5 and i´ve seen some strange things, like diferent ways to read a
collection of rows, magic functions, wrapers, and operators like  
:: and
-. I know that all is the manual, but before that anyone nows, a  
website
or a simple tutorial or explained samples, in order that the  
transition from

PHP4 and PHP5 were easiest as possible.


Many of the things you mention are not new in PHP5. This will help:

http://www.zend.com/php5/migration.php

If you want a book:

http://www.oreilly.com/catalog/upgradephp5/

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] mod_rewrite and include paths

2005-11-14 Thread Marcus Bointon


On 14 Nov 2005, at 18:51, Richard Lynch wrote:


include_path(/full/path/to/DocumentRoot: . include_path());
This may not be the right syntax/function to set include_path, but it
is a dynamic way to set the include path, from within PHP.


Yup, I tried this and it kind-of works, but still leads to some weird  
behaviour.



INSTEAD, do this.

Create a PHP script, and name it 'x'

In .htaccess, force 'x' to be PHP as far as Apache is concerned:
Files x
  ForceType application/x-httpd-php
/Files

You can now access your x=123 from $_SERVER['PATHINFO'] (or is it
'PATH_INFO'?

No more endless tweaking of Regex rules in httpd.conf and logging the
mod_rewrite and dinking with ^/[0-9]+ junk and re-starting Apache
every time you want to try a change.


That's a nice trick - I'll have to remember that. My rules are  
in .htaccess (as seems normal for 'deployable' systems) so I don't  
need to restart apache and it's easy to twiddle with them, and  
besides, I like regexes ;^) The issue isn't really the passing of  
parameters (which your approach deals with very nicely), it's that  
PHP gets fooled into thinking that it's somewhere that it's not. The  
most annoying thing about this problem is that I'm sure it should  
'just work', and I know I've seen it do so before in both my scripts  
and others - Serendipity has an almost identical setup for rewrites  
and it doesn't do anything special to work with them - all this  
futzing with paths that mod_rewrite does is long finished by the time  
that PHP gets to hear about anything - PHP never has to know the real  
URL, it should be happy to deal with the rewritten one.


The problem seems to be that given the incoming URL:

/x/123

this gets rewritten to

/x.php?x=123

and it does run the correct script in the correct directory, however,  
once it's running PHP acts as if it had said:


/x/x.php?x=123

Which just breaks paths everywhere. I know that this is what the  
passthrough option is supposed to deal with, but removing it doesn't  
help either. Maybe I should look more carefully at my RewriteBase etc.


I've asked in sitepoint apache forums too, see if anyone there has  
any idea.


Thanks for the ideas.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Printing to a buffer

2005-11-14 Thread Marcus Bointon

On 14 Nov 2005, at 19:01, Richard Lynch wrote:


It may not be my final choice whether they download or not, but if a
browser doesn't treat:
application/octet-stream
as a download, and only as a download, then that browser is pretty
broken.

Letting the user configure their browser for that MIME type to be
opened by an application is just plain wrong for a browser, by
specification.

If you find a browser that lets you configure application/octet-stream
to be opened with a specific application, then file a bug report with
whomever wrote that browser.


There's no such spec for browsers per se (which is why they vary so  
much) - they are just HTTP clients. I can think of a perfectly  
reasonable situation where I would want a plugin to handle  
application/octet-stream - say I'm pulling some arbitrary binary data  
and while I'm debugging, an in-browser hex dump could be very useful.  
The other thing is that I may be being forced to use that 'wrong'  
MIME type to work around bad implementations of content- 
disposition... I know that's not a common situation, but there should  
be nothing preventing me from doing it. There are browsers that don't  
do downloads at all (I've written some), there are others that do  
nothing but downloads (I use Interarchy for just that). I could offer  
a similar opinion about the browsers that have odd implementations of  
content-disposition.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Recommendations for the Zend PHP Certification

2005-11-13 Thread Marcus Bointon

On 12 Nov 2005, at 16:29, Gustavo Narea wrote:


  - Zend PHP Certification Study Guide.


This book would be good if it were not so full of errors. With a bit  
of luck it's been revised since my edition (July 2004 printing); I  
noticed quite a few problems and then found a huge errata list on  
their site.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Printing to a buffer

2005-11-13 Thread Marcus Bointon


On 13 Nov 2005, at 00:17, Jasper Bryant-Greene wrote:

seem to do that.  I just tried application/text since I use  
application/pdf for other applications.


Whatever it's giving the user the ability to do, it's probably  
because the browser doesn't recognise the (invalid) MIME-Type.


Quite - it's right up there with 'application/force-download'. If you  
want to suggest (the final choice is not yours to make) that a  
browser might download something instead of displaying it, set an  
appropriate content-disposition header instead of setting the wrong  
type.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Printing to a buffer

2005-11-13 Thread Marcus Bointon

On 13 Nov 2005, at 19:27, Jasper Bryant-Greene wrote:


Many thanks!  I did not know that MIME-Type.  Change duly made!


You're not suggesting that you actually set the MIME-Type to  
application/force-download, are you?


I think he is. I've called the MIME-type police and they'll be round  
later.


Todd, I think you should read this: http://support.microsoft.com/kb/ 
q260519/


There's a PHP example just before the user notes here: http:// 
www.php.net/header


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] mod_rewrite and include paths

2005-11-13 Thread Marcus Bointon

This seems like a simple problem...

I have a rewrite like this:

RewriteRule ^x/([0-9]+) x.php?x=$1 [PT,L]

This maps a url like http://www.example.com/x/123 to http:// 
www.example.com/x.php?x=123


x.php contains a line to include some class like:

require_once 'x.class.php';

My include path contains '.' (plus paths to pear, etc), and the class  
file is in the top level directory.


This configuration will fail with a file not found error. Because of  
the rewrite, PHP ends up looking for x/x.class.php instead of just  
x.class.php. If I change the PT option to R (AKA ugly mode), it works  
fine as PHP gets to know about the real URL.


So how can I get PHP to look in /? I can set include_path with a  
php_value in .htaccess, but I can only set it absolutely (losing  
existing values), not add to it (AFAIK?). I don't want to add an  
absolute path to my global include_path as there may be multiple  
independent deployments of the same scripts on the server, and I  
don't want them including each others files. Adding .. to the path  
would work but is a security risk. Any other ideas?


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] mod_rewrite and include paths

2005-11-13 Thread Marcus Bointon

On 13 Nov 2005, at 22:15, Marco Kaiser wrote:

try to use realpath, dirname and other related funktion to resolv  
the real path.


dirname(__FILE__) ?


Good point (you can tell I've been up too long). I've just had a play  
with that - I appended the current path to my include_path, but it  
seems it's not inherited, so sub-includes are not found. I also tried  
chdir(dirname(__FILE__)) which had the same results and interferes  
with the operation of require_once (the same file found by a  
different path doesn't get counted as the same file). Incidentally  
doing just 'echo getcwd();' seems to fail completely when called via  
a rewrite. After all that, smarty still can't find its templates_c  
for some reason. I'm sure there must be something simple and elegant  
I'm missing. Probably a good night's sleep.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] mod_rewrite, apache2, php5RC1 and osx bsd

2005-11-11 Thread Marcus Bointon

On 10 Nov 2005, at 21:36, Richard Lynch wrote:


On Wed, November 9, 2005 10:36 pm, Dan Rossi wrote:

RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.+\.(video))$
../../phpscript.php


I should think all those .* should be .+ instead...

I mean, if somebody surfs to this URL:

http://example.com//example.video


There's nothing really wrong with a URL like that, and I used to do  
the same thing until I discovered another fly in this particular  
ointment. Should source URLs like these ever appear in Microsoft  
Outlook, they are likely to get 'corrected', for example a URL that  
goes in as:


http://example.com//example.video

When you click it, you're quite likely to have it go to:

http://example.com/example.video

thus completely missing all your mod_rewrite patterns. This is why we  
love MS so. I've taken up using _ as a pattern separator as a  
workaround.


There's also a very nasty bug in current mod_rewrite (at least in  
Apache 2.0.54) where mod_rewrite url decodes submatches between input  
and output URLs, so for example:


RewriteRule ^(.*) blah.php?x$1

if you feed that a URL that contains a URL encoded value like 'Hello% 
20there', your resulting URL will be: 'blah.php?x=Hello there', which  
is obviously broken.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] php session in ie

2005-11-11 Thread Marcus Bointon

On 11 Nov 2005, at 11:43, sunaram patir wrote:


 it works fine in firefox and msn explorer. in internet explorer, when
i visit to a
link in any page it asks for the login details again. could anyone
please help me out?!


It just sounds like you have cookies disabled or not allowed for this  
site in IE.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Sessions and register_long_arrays

2005-11-05 Thread Marcus Bointon

On 5 Nov 2005, at 00:25, Unknown Unknown wrote:

how do you reference the sessions? do you refrence them *with* the  
old arrays? because that would obviously be a problem


No, obviously that would be dumb! There is no mention of the old  
style HTTP_*_VARS arrays anywhere in my code. Smarty does use them by  
default, but I've turned that off. I'm also avoiding old-style  
session_register, only using current functions like session_start,  
session_name, session_destroy and putting everything in $_SESSION.


Someone pointed me at his bug:

http://bugs.php.net/bug.php?id=34542

I've been trying to come up with a small test case but no luck so far  
(so the bug remains with feedback status). xdebug is now working  
under 5.1RC5-dev but it doesn't trace quite how I thought it did. I  
suspect we might have more bug reports if more people were turning  
register_long_arrays off!


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: Richard Lynch's Email Address ...

2005-11-03 Thread Marcus Bointon

On 3 Nov 2005, at 04:32, viraj wrote:


does PHP really needs a function to validate an email address!! i
doubt. because PHP is a language which provides number of string
functions with regex capabilities to develop what ever pattern
matching you want.


Writing a regex for RFC2822 is not easy - the format is extremely  
flexible. Having said that, I've got on very well using these:


http://www.hexillion.com/samples/#Regex

Though it doesn't deal with that oddity that Richard mentioned.

The PEAR rfc822 class is pretty good, but it should be noted it's  
designed for parsing entire to, cc, bcc fields which may contain  
multiple addresses, and it's not quite as simple as asking it 'is  
this address ok'.



second point is, different organizations have different policies on
validating email addresses, so again those developers have to mend
their own mechanisms. so everybody will not benefit this effort.


Well, unless you're counting really different addressing standards  
like X.500, everyone has to operate within RFC2822. You're quite free  
to put additional constraints on addresses, but should be within that  
spec, not in addition to it. If an address is not RFC2822 compliant,  
it's pretty unlikely to work, though I have occasionally seen things  
like non-ASCII chars and '_' get through.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: Richard Lynch's Email Address ...

2005-11-03 Thread Marcus Bointon

On 3 Nov 2005, at 14:16, Richard Heyes wrote:

It even has a method specifically for normal email addresses of  
the form [EMAIL PROTECTED]


Ah, well, that's good news. It's been a while since I looked at it.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] [DONE] Substr by words

2005-10-31 Thread Marcus Bointon

On 31 Oct 2005, at 06:27, Richard Lynch wrote:


There's a certain point where the Regex expression reaches a level of
complexity that I'm just not willing to accept in my code and call it
maintainable

/  */ is fine, of course.

But there's lots of times when I know there must be a one-line regex
to replace 10 lines of code, but I don't WANT to use it because I'll
stumble over that one-line Regex every time I have to change it.


I quite agree that many regexes are 'write only', but I don't think  
that that means that using substr and friends is necessarily any  
clearer. I sometimes find that a nested mass of string functions is  
even more confusing - at least a regex has a fixed grammar. I've just  
written a load of stuff that uses preg_replace_callback that I'm  
quite pleased with.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Type of form element

2005-10-31 Thread Marcus Bointon

On 31 Oct 2005, at 06:18, Richard Lynch wrote:

But I really do believe isset($_POST['checkbox_name']) is a good  
coding practice.


OK, so PHP may not pass through unset params as NULL (it's not up to  
the browser), but if you don't select any checkboxes at all, the  
param won't exist, and asking for an index of something that doesn't  
exist is normally a good way to generate notices. isset's job is not  
to tell you if an array key exists, so why use it for that purpose?


This is the difference I'm on about:

$z = array('a' = 1, 'b' = NULL);
echo array_key_exists('a', $z)?yes\n:no\n;
echo isset($z['a'])?yes\n:no\n;
echo array_key_exists('b', $z)?yes\n:no\n;
echo isset($z['b'])?yes\n:no\n;

This prints:

yes
yes
yes
no

That last 'no' has huge bug potential.

I'm not saying it doesn't have practical use, but I wouldn't call it  
good practice, and I wouldn't advise people to do it that way in new  
code. As it happens, isset _will_ usually work for things that come  
through the web-driven superglobals, but not all arrays come from  
there - if you use the same syntax for dealing with databases or your  
own objects you could be creating some very entertaining bugs. I  
don't know about you but I often deal with arrays containing NULL  
values where using isset would be very wrong.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: Substr by words

2005-10-31 Thread Marcus Bointon


On 31 Oct 2005, at 03:29, Gustavo Narea wrote:

I think It is OK what I said about the caret, but what we need to  
change is the position of \W*:

   Your suggestion: /(\b\w+\b\W*){1,$MaxWords}/
   My suggestion: /^(\W*\b\w+\b){1,$MaxWords}/

We need the *first* ($MaxWords)th words.


I makes no difference - they will both work. Mine doesn't care where  
the first word starts because it doesn't use ^, and yours doesn't  
care where the first word starts because it's got ^ followed by \W*.  
Your overall match will end up with leading spaces, mine will end up  
with trailing spaces - the subsequent trim fixes them both. I like  
mine because it has 1 less char ;^)


Ultimately, if it works for you, great!

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] php mail function vs smtp server

2005-10-31 Thread Marcus Bointon

On 31 Oct 2005, at 10:34, Richard Heyes wrote:

Depends on your setup. If you're on Linux/Unix you could use the  
mail() function along with the -odq option to Sendmail/Postfix/ 
Exim etc (fifth argument to the mail() function) which will dump  
all the mails into the MTAs queue. After this, the MTA will handle  
delivery. This is probably the quickest for this platform.


I agree. Sending directly is usually reserved for Windows machines  
with no local MTA and is usually way slower and doesn't handle  
queuing. I'd advise anyone to use PHPMailer for mail anyway as it  
makes it much more reliable to deal with all the other stuff like  
MIME encoding, plus it has support for all these sending methods  
without having to change much code. I use it with qmail.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Type of form element

2005-10-31 Thread Marcus Bointon

On 31 Oct 2005, at 14:54, Chris Shiflett wrote:

Hopefully it is also clear that your argument revolves around the  
idea that PHP would create $_POST['foo'] as NULL if the checkbox is  
not checked. This is wrong for two reasons:


No, no, that's not what I said - I wouldn't contemplate such  
silliness! The thing I was wrong on is that PHP converts unset  
parameters (as opposed to nonexistent ones which it obviously can't  
do anything about) to an empty string, e.g. given ?a=b=1, $_REQUEST 
['a'] is , not NULL. However, it still serves to underline my other  
point that using isset without actually knowing that is a potentially  
dangerous thing. Getting into the habit of using it for looking in  
the likes of $_REQUEST means you're likely to use it other places  
where you have no such guarantee, and you'll have a bug to track  
down. Using array_key_exists means you will never be exposed to this  
possibility, no matter where your data comes from.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Type of form element

2005-10-31 Thread Marcus Bointon

On 31 Oct 2005, at 17:55, Richard Lynch wrote:


You're wrong.


No. You're just missing what I'm on about. I'll agree it's very dull.


isset() does not, under any circumstances, create an index nor a
variable.


Quite right; I never said it did.

Its entire purpose *IS* to tell you if something has been set to a  
value.

That's why it's CALLED isSet


But that's not the question you're using isset to answer. You just  
want to know if something exists - you probably don't even care what  
its value is.


Take apart this operation:

$a = isset($myarray['a']);

Implicit in this simple line is a 'hidden' step which is to look up  
the index 'a' in $myarray to get its value before testing if it is  
set or not. The issue I have is that that step's existence is being  
overlooked. That line could also be written:


$a = !is_null($myarray['a']);

Either way, if $myarray['a'] does not exist, its value will be  
regarded as null (and as such, isset and !is_null would give correct  
results as a consequence of this convenient side-effect), but I would  
also fully expect to receive an undefined index notice as you have  
explicitly looked up an array index that does not exist. If you used  
other functions the same way you're using isset, you would see  
nothing wrong with this:


$myarray = array();
print $myarray['a'];

but I would hope that you would have a problem with that. Why treat  
isset differently?


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Type of form element

2005-10-31 Thread Marcus Bointon


On 31 Oct 2005, at 21:11, Chris Shiflett wrote:

I think this is where some (most?) of the misunderstanding  
originates. Testing to see whether something exists is exactly what  
isset() does.


No. Given $myarray['a'] = NULL, isset($myarray[a']) returns false.  
You're saying that therefore, $myarray['a'] does not exist, which is  
clearly untrue. Testing to see whether something has a value is  
exactly what isset does, not whether it exists. In many cases it  
comes down to the same thing (because if it doesn't exist it can't  
have a value), but they are definitely not identical.


Wouldn't it seem like a bug if a function intended to check whether  
a variable is set generates a notice when you test a variable that  
isn't?


Since we're on such thin ice, you need to tread carefully - first you  
said it's for testing to see whether something exists, but now you  
describe it as a function intended to check whether a variable is  
set. Which is it? They are not the same thing. Here's an experiment  
to distinguish which it is - it may come as quite a surprise:


var_dump(isset($bar));
echo $bar;
$bar = NULL;
var_dump(isset($bar));
echo $bar;


bool(false)
PHP Notice:  Undefined variable: bar in /test.php on line 3
Notice: Undefined variable: bar in /test.php on line 3
bool(false)

Holy Smoke! isset quite definitely CANNOT tell you if a variable does  
not exist - though PHP clearly knows as the second echo did not  
generate an error! If it returns true then it does definitely both  
exist and has a value (which is useful and why you can use isset as  
you do), but if it returns false you really have no idea if the var  
exists or not. So what can you use instead? Is there no direct  
equivalent of array_key_exists for variables? I did discover that  
array_key_exists('bar', get_defined_vars()) works, but though at  
least it's definitive, I don't think I could face using that  
everywhere ;^)


To summarize, I see nothing wrong with your way of using  
array_key_exists(), but I don't think you can claim Richard's use  
of isset() is inappropriate. His method is safer in cases where  
the array itself is not set, and your method is safer when an  
element's value is NULL. Neither of these cases ever exist with  
$_GET, $_POST, etc., because they are always set, and they only  
contain strings. Therefore, there's no debate to be won here. :-)


Of course isset has a valid place - array_key_exists cannot replicate  
what it does (it doesn't know about values), so they can play  
together nicely - for example I'd consider this pretty robust:


if (isset($_SESSION) and is_array($_SESSION) and array_key_exists 
('myvar', $_SESSION)) ...


If you get past that you can be absolutely certain that $_SESSION 
['myvar'] exists, regardless of its value, and there is no  
opportunity to trigger an error, whereas if you said:


if (isset($_SESSION) and is_array($_SESSION) and isset($_SESSION 
['myvar'])) ...


you could still be wrong. The merest possibility of being wrong is a  
bad thing in code. Why not use marginally different syntax and be  
absolutely sure?


Yesterday I encountered an error in a large commercial php script and  
it turned out that it was looking in $_SERVER['SERVER_NAME'] which  
was there but set to NULL for some reason, and their test with isset  
was failing. So it's not just academic and I'm not making it up -  
this problem does happen for real.


All this over such a little thing - imagine if we had a whole  
language to worry about! Oh wait...


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Type of form element

2005-10-30 Thread Marcus Bointon

On 29 Oct 2005, at 20:59, Richard Lynch wrote:


So you will most likely be using isset($_POST['checkbox_name']) rather
than testing for on


I classify using isset for checking for the existence of array keys  
to be a bad habit as in some common cases it will not work as you  
expect, for example:


input type=checkbox name=checkbox_name /

(note it has no value attribute) If it's checked, you would get the  
equivalent URL of ...?checkbox_name=, so $_REQUEST['checkbox_name']  
exists, but may contain NULL, and isset would return false even  
though it's there. A completely reliable check that will never  
generate any warnings is:


array_key_exists('checkbox_name', $_REQUEST).

If you have several checkboxes in an array (using names like  
name=checkbox_name[option1]), you would say:


if (array_key_exists('checkbox_name', $_REQUEST) and is_array 
($_REQUEST['checkbox_name'])) {

if (array_key_exists('option1', $_REQUEST['checkbox_name'])) {
echo you selected option 1\n;
}
if (array_key_exists('option2', $_REQUEST['checkbox_name'])) {
echo you selected option 2\n;
}
//etc...
}

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] [DONE] Substr by words

2005-10-30 Thread Marcus Bointon

On 29 Oct 2005, at 20:41, Richard Lynch wrote:


It was probably replacing *TWO* spaces with one.

If so, it should really be in a while loop, because there could be 3
or more spaces in a row, and if the goal is only single-spaced
words...


I can hardly think of a better application for a regex:

$text = preg_replace('/  */', ' ', $text);

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: Substr by words

2005-10-30 Thread Marcus Bointon

On 30 Oct 2005, at 06:22, Gustavo Narea wrote:

$replacement = ereg_replace (^([[:space:]]*[^[:space:][:cntrl:]]+) 
{1,$MaxWords}, ,$MyOriginalString);


echo substr( $MyOriginalString, 0, ($replacement) ? -strlen 
($replacement) : strlen($MyOriginalString));


You could get the regex to do the search and the extraction in one go:

$MyOriginalString = This is my original string.\nWhat do you think  
about this script?;

$MaxWords = 6; // How many words are needed?
$matches = array();
if (preg_match(/(\b\w+\b\W*){1,$MaxWords}/, $MyOriginalString,  
$matches)) {

$result = trim($matches[0]);
echo $result;
}

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] php not activated

2005-10-30 Thread Marcus Bointon

On 30 Oct 2005, at 14:13, John Taylor-Johnston wrote:


echo $contents;


PHP doesn't now that it's PHP - it just treats it as text. You can  
tell it to run it as PHP explicitly using:


eval($contents);

Eval is usually worth avoiding, but it will do what you ask.

Your display function could be improved:

function display()
{
   $file = basename($_SERVER['PHP_SELF']);
   require 'connect.inc';
   $sql = SELECT HTML FROM `$db`.`$table_editor` WHERE `Filename`  
LIKE '.addslashes($file).' LIMIT 1;;

   if ($myquery = mysql_query($sql) and mysql_num_rows($myquery)  0) {
   $mydata = mysql_fetch_array($myquery, MYSQL_NUM);
   return $mydata[0];
   }
   return false;
}

Then call it:

if ($contents = display())
eval($contents);

This should be faster and safer than your original code.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: Substr by words

2005-10-30 Thread Marcus Bointon


On 30 Oct 2005, at 15:35, Gustavo Narea wrote:

I think that trim($matches[0]) will return the whole string with no  
change.


No, it will return the entire matching pattern, not just the sub- 
matches. I added the trim to remove any leading space, and there will  
nearly always be a trailing space because of the part of my pattern  
that defines a word will include it. It was simpler to use trim than  
to make the pattern skip it. Did you actually try it?


On the other hand, I think we have to place a caret after the first  
slash.


Only if you insist that your string must start with a word - putting  
a ^ at the start would make it omit the first word if there was a  
space in front if it.



Instead of preg_match(), I had to type preg_replace():


err. I think you missed the point here. You don't need all that messy  
substr stuff at all. The preg_match already did it.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Sessions and register_long_arrays

2005-10-29 Thread Marcus Bointon
Strange behaviour that's taken me ages to track down. I have the  
situation where I can create a session, but any changes to it are not  
saved. session_write_close() didn't help. Eventually I tracked it  
down: if you have register_long_arrays disabled (as is the default in  
PHP5), this can happen. Enabling it fixed the problem. A very simple  
test case didn't show this problem, so I guess something in my  
sessions has a dependency on HTTP_GET_VARS or similar, though these  
old-style vars do not appear anywhere in my code... Some of the  
libraries I'm using may use them (for example Smarty, though I have  
the request_use_auto_globals option enabled for that which should  
stop it using them), but nothing to do with them is stored in the  
session. If I look at a session file, it's all just scalars and  
arrays, no complex types at all, but changing an item in $_SESSION  
simply does not get saved back to the session file if  
register_long_arrays is enabled.


Anyone else seen this? Any idea why it might be happening?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Sessions and register_long_arrays

2005-10-29 Thread Marcus Bointon

On 29 Oct 2005, at 14:48, Marcus Bointon wrote:

changing an item in $_SESSION simply does not get saved back to the  
session file if register_long_arrays is enabled.


I meant disabled.

I've also tried using it with the mm session save handler and I get  
the same symptoms. I also get identical results on OS X and Linux.


FYI, I want to disable this setting for increased performance,  
especially as I'm not using these old arrays anyway.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] PHP version check

2005-10-28 Thread Marcus Bointon


On 28 Oct 2005, at 07:46, Richard Davey wrote:


Friday, October 28, 2005, 7:41:21 AM, you wrote:


How can I query for PHP version?


phpversion() !


While it's true that that will get you a version string, if you're  
going to actually check it, you need:


http://www.php.net/manual/en/function.version-compare.php

to do so reliably. Version strings are messy things.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] prevent user from getting scripts outside the web folder [this better?]

2005-10-14 Thread Marcus Bointon

On 14 Oct 2005, at 04:48, David Robley wrote:

That is incorrect. mysql_real_escape_string is a php function, not  
mysql.


Mostly true: mysql_real_escape_string is a php function, but it's  
provided by the mysql extension as part of the mysql client libraries  
(which explains the name). It doesn't do anything significantly  
different to addslashes(), which is purely a PHP internal function.  
If you are writing database independent code, you should probably  
prefer addslashes (or things like adodb::qstr).


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] OPTIMIZING - The fastest way to open and show a file

2005-10-14 Thread Marcus Bointon

On 14 Oct 2005, at 12:29, Ruben Rubio Rey wrote:

* For files less or equal 6 Kb, takes arround 0.02-0.03 miliseconds  
- its ok
* For files arround 35 Kb takes arround 0.2-0.4 miliseconds - too  
much.


Bearing in mind that average access time on a 7200rpm HD is around  
8ms, those numbers sound too good to be true anyway. You could  
configure some kind of software disk cache on your system, or ideally  
a hardware caching RAID controller and it could improve things  
dramatically, but not down to that kind of level (which represents  
about 200x what a single disk system might be expected to deliver).


Otherwise as Jochem says, use RAM for your cache in the first place.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Re: ampersand in dom with utf-8

2005-10-13 Thread Marcus Bointon

On 13 Oct 2005, at 07:24, cc wrote:


both `egrave;' and `icirc;' are not entities in charset utf-8, use
`amp;egrave;' and `amp;icirc;' instead.


I would expect that to result in unconverted entities in the output.  
If you're intending to send that content as HTML, then I guess that  
would be OK. However, if you're using UTF-8 anyway, why not just use  
the real characters?


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] SOAP WSDL location

2005-10-12 Thread Marcus Bointon
This is a minor thing that's been troubling me, making it difficult  
to deploy a salesforce.com SOAP client across multiple projects.  
Salesforce is a particular interest because its WSDL files are NOT  
available directly online - you have to download and save local  
copies manually.


When constructing a SOAPClient object, the WSDL parameter provided is  
treated like a URL (because it will usually BE a URL). For 'local'  
URLs, it searches the current directory, including any relative path  
that it uses. However, because it is fundamentally a URL and not a  
file request like an include, it does not search the include path.  
The net result of this is that I'm having to copy my WSDL files into  
every place that my class library is called from because the URL  
resolution will only ever look in the calling directory and not in  
the include path that allowed it to find my classes.


An alternative would be to allow providing the WSDL as a literal  
string, probably read using file_get_contents() which does support  
using the include path.


A worse solution is to provide the WSDL contents as the response to a  
separate HTTP call (i.e. act like the WSDL is online after all). This  
would work, but it's way less efficient.


I can't use an absolute path as it's deployed in multiple  
configurations on multiple servers, and config is bad enough already.


Now before I report this as a bug/feature request, does anyone have  
any better ideas?


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Global unavailable?

2005-10-05 Thread Marcus Bointon

I have a simple situation:

in a.inc.php:

$a = 1;

in b.class.php

require 'a.inc.php';
class b {
function test() {
global $a;
echo $a;
}
}

With this pattern, $a is NOT visible within class b, even though it  
is declared in the global scope and I'm using the global keyword! I  
can work around it two ways; by changing the original declaration  
(which just seems wrong - it's already in the global scope at this  
point):


global $a;
$a = 1;

or by requiring the inc file inside each function of b (much less  
efficient):


class b {
function test() {
require 'a.inc.php';
global $a;
echo $a;
}
}

Is this just how it is, or am I doing something wrong?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Global unavailable?

2005-10-05 Thread Marcus Bointon

On 5 Oct 2005, at 13:37, Jochem Maas wrote:


if changing the declaration in a.inc.php fixes it then you must
NOT be including b.inc.php form the global scope.


Well, that's what I thought, but it just isn't! The include really is  
in the global scope outside any class or function definition. The  
original definition is directly inside the included file, and not  
itself inside a function or class.


I should have mentioned that I'm using PHP 5.1-dev, so it could just  
be  bug...


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] OS X compile problem with GD

2005-08-30 Thread Marcus Bointon
I've suddenly developed a peculiar compile problem in PHP5. I'm  
trying to build PHP 5.0.4, 5.0.5RC1, 5.0.5RC2 or 5.1RC1, and they  
have started giving me an odd problem with GD:


gcc -I/Users/marcus/src/php-5.0.4/ext/gd/libgd -DHAVE_LIBPNG - 
DHAVE_LIBJPEG -DHAVE_LIBFREETYPE -Iext/gd/ -I/Users/marcus/src/ 
php-5.0.4/ext/gd/ -DPHP_ATOM_INC -I/Users/marcus/src/php-5.0.4/ 
include -I/Users/marcus/src/php-5.0.4/main -I/Users/marcus/src/ 
php-5.0.4 -I/usr/include/libxml2 -I/sw/include -I/sw/lib/freetype219/ 
include -I/sw/lib/freetype219/include/freetype2 -I/Users/marcus/src/ 
php-5.0.4/ext/mbstring/oniguruma -I/Users/marcus/src/php-5.0.4/ext/ 
mbstring/libmbfl -I/Users/marcus/src/php-5.0.4/ext/mbstring/libmbfl/ 
mbfl -I/usr/local/mysql/include -I/sw/include/libxml2 -I/Users/marcus/ 
src/php-5.0.4/TSRM -I/Users/marcus/src/php-5.0.4/Zend  -I/sw/include - 
no-cpp-precomp  -DBIND_8_COMPAT=1 -DEAPI -O3 -mcpu=G4 -mtune=G4 -I/sw/ 
include  -c /Users/marcus/src/php-5.0.4/ext/gd/gd.c -o ext/gd/gd.o   
 echo  ext/gd/gd.lo

/Users/marcus/src/php-5.0.4/ext/gd/gd.c: In function 'zm_info_gd':
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:504: error: 'FREETYPE_MAJOR'  
undeclared (first use in this function)
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:504: error: (Each undeclared  
identifier is reported only once
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:504: error: for each function  
it appears in.)
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:504: error: 'FREETYPE_MINOR'  
undeclared (first use in this function)

/Users/marcus/src/php-5.0.4/ext/gd/gd.c: In function 'php_imagechar':
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:2810: warning: pointer  
targets in passing argument 1 of 'strlen' differ in signedness
/Users/marcus/src/php-5.0.4/ext/gd/gd.c: In function  
'php_imagettftext_common':
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:3189: warning: pointer  
targets in passing argument 4 of 'gdImageStringFTEx' differ in  
signedness
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:3189: warning: pointer  
targets in passing argument 9 of 'gdImageStringFTEx' differ in  
signedness
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:3195: warning: pointer  
targets in passing argument 4 of 'gdImageStringFT' differ in signedness
/Users/marcus/src/php-5.0.4/ext/gd/gd.c:3195: warning: pointer  
targets in passing argument 9 of 'gdImageStringFT' differ in signedness

make: *** [ext/gd/gd.lo] Error 1

I tried switching from the bundled GD to a version compiled from  
fink, but it made no difference. My current configure is:


'./configure' \
'--with-layout=Darwin' \
'--bindir=/usr/bin' \
'--disable-ipv6' \
'--enable-bcmath' \
'--enable-calendar' \
'--enable-dba' \
'--enable-exif' \
'--enable-ftp' \
'--enable-gd-imgstrttf' \
'--enable-gd-native-ttf' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-mcal' \
'--enable-pcntl' \
'--enable-shmop' \
'--enable-soap' \
'--enable-sockets' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--enable-track-vars' \
'--enable-wddx' \
'--sysconfdir=/etc' \
'--with-apxs2filter=/sw/sbin/apxs' \
'--with-bz2' \
'--with-config-file-path=/etc' \
'--with-config-file-scan-dir=/etc/php.d' \
'--with-curl' \
'--with-db4=/sw' \
'--with-dom=/sw' \
'--with-freetype-dir=/sw/lib/freetype219' \
'--with-gd=/sw' \
'--with-gdbm=/sw' \
'--with-iconv=/sw' \
'--with-imap-ssl=/sw' \
'--with-jpeg-dir=/sw' \
'--with-png-dir=/sw' \
'--with-ldap' \
'--with-mcrypt=/sw' \
'--with-mhash=/sw' \
'--with-mysql=/usr/local/mysql' \
'--with-mysqli=/usr/local/mysql/bin/mysql_config' \
'--with-openssl' \
'--with-pcre=/sw' \
'--with-pear' \
'--with-png' \
'--with-tidy=/sw' \
'--with-ttf' \
'--with-xml' \
'--with-xmlrpc' \
'--with-xsl' \
'--with-zlib' \
'--without-oci8'

you can see that I'm pulling in a fair number of things form fink,  
but until recently it was all working fine with 5.0.4. There are only  
two options that affect gd directly: --with-gd and --with-freetype- 
dir. The configure script doesn't report any problems:


...
checking for GD support... yes
checking for the location of libjpeg... /sw
checking for the location of libpng... /sw
checking for the location of libXpm... no
checking for FreeType 1.x support... yes
checking for FreeType 2... /sw/lib/freetype219
checking for T1lib support... no
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... (cached) yes
checking for floorf... (cached) yes
checking for jpeg_read_header in -ljpeg... (cached) yes
checking for png_write_image in -lpng... (cached) yes
If configure fails try --with-xpm-dir=DIR
checking for FreeType 1 support... no - FreeType 2.x is to be used  
instead

...

Any idea why this is not working?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Looking for CMS advice

2005-08-23 Thread Marcus Bointon

On 23 Aug 2005, at 14:05, Jay Paulson wrote:


I would say check out Dupral, Mambo, and XOOPS.


Drupal looks great, but whenever I've tried to get into it, nothing  
seems to work properly. Xoops is capable (I've used it on a couple of  
sites), but generally a complete mess internally. Both of them have  
massive, cryptic control panels and it's inordinately complicated to  
do simple things like put this bit of text at the top of the front  
page. Unless you want your site to look and work like everyone  
else's Nuke clone, I'd steer clear of these.


The majority of so-called content management systems actually fail  
dismally at managing content. I don't know why they even use the name.


For simple sites, Website Baker is great, especially if the intended  
admin wants little hassle. It's one of the few that seems to put a  
strong emphasis on usability over feature bloat.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] __sleep, __wakeup and persistent connections

2005-08-20 Thread Marcus Bointon
I'm sorting out some code to handle session object storage,  
particularly where the objects contain DB connections. I've found  
lots of articles that go on about how __sleep should clean up db  
stuff, close connections etc and how __wakeup should reconnect, but  
weirdly enough I've not found a single concrete example of doing this!


It's also not quite clear how this behaviour interacts with  
persistent connections. For example, If I do this:


class foo {

protected $db;

public function __construct() {
$this-db = mysql_pconnect();
}

protected function __wakeup() {
$this-db = mysql_pconnect();
}

protected function __sleep() {
mysql_close($this-db);
$this-db = NULL;
return array();
}
}

given that the connection is persistent, and may thus be used by  
other scripts, is calling mysql_close a particularly bad idea? Should  
I just not bother closing the connection, letting PHP deal with it -  
the object will not attempt to re-use the stale connection because it  
will get a new instance courtesy of __wakeup when unserialized.


I'm also unclear about how __sleep acts in subclasses - it seems that  
as soon as I have a __sleep function in a base class, I don't have  
any choice but to implement __sleep functions in every subclass of  
it, even if I don't want them to do anything that would not be done  
if __sleep were not defined. in the exampel, the base class has no  
properties to save, so it returns an empty array from __sleep, but  
that's unlikely to be useful for a subclass that does have properties  
(and serializing an object without any properties is pointless!).


Ideas?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] parallel execution of php code?

2005-08-09 Thread Marcus Bointon

On 8 Aug 2005, at 16:07, Martin van den Berg wrote:


$query = SELECT id FROM mytable WHERE bla LIKE  . $x .;
$rows = execute( $query )
if ( $rows == 0 )
{
   /* some more processing */
  $query = INSERT INTO mytable .. etc etc
  execute( $query )
}


I have lots of places where I used to do this. Since MySQL 4.1 I've  
changed it to something like:


INSERT INTO mytable SET id = 123, bla = '$x' ON DUPLICATE KEY UPDATE  
bla='$x'


This saves you a query, and makes it easier to isolate the insert/ 
update as it will play nicely with autocommit.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Fast count of recordset in php...

2005-08-07 Thread Marcus Bointon

On 7 Aug 2005, at 05:04, TalkativeDoggy wrote:


be coz this way is slow and costs more overload.

   $sql = SELECT COUNT(IDVara) cn FROM tbvara WHERE Varunamn LIKE  
'$checkLev%';

   $querys = mysql_query($sql);

   //Count products in db
   //
   $dbArray = mysql_fetch_row($querys);
   $nrOfProducts = $dbArray[0];


According to the docs, MySQL has a particular optimisation that means  
that it should be:


 $sql = SELECT COUNT(*) FROM tbvara WHERE Varunamn LIKE '$checkLev%';

Also if you want the full count value when you've done a query that  
uses a LIMIT clause, instead of doing a separate full count query,  
you can get it by using the SQL_CALC_FOUND_ROWS keyword, e.g.


$sql = SELECT SQL_CALC_FOUND_ROWS * FROM tbvara WHERE Varunamn LIKE  
'$checkLev%' LIMIT 10;


Of course count(*) could only ever return up to 10 in this query -  
you can find out how many it would have found by then asking:


$sql = SELECT FOUND_ROWS();

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Regex help

2005-08-03 Thread Marcus Bointon

On 2 Aug 2005, at 15:12, Robin Vickery wrote:


I don't suppose this is the place for a rant about the futility of
checking email addresses with a regexp?


Though I will agree with you to some extent, I've had quite a lot of  
success with this, which is pretty thorough:


^(?:[\w\!\#\$\%\\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\\'\*\+\- 
\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61} 
[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)| 
(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4] 
\d|25[0-5])\]))$


Which I got from here:

http://www.hexillion.com/samples/#Regex

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] function with argument of type array

2005-07-29 Thread Marcus Bointon

On 29 Jul 2005, at 08:19, Jochem Maas wrote:

unless String is a class you defined that won't work at all. basic  
data types

cannot be hinted (e.g. bool, int, string, float)


There's been quite a bit about this on php-internals. It seems to be  
because PHP doesn't differentiate between these types internally;  
they all seem to be classified as a generic scalar type whose actual  
type is determined according to context. Java can go to the other  
extreme, where every simple type is an object, and hence it's easy  
(if not mandatory) to specify types like this. You would never be  
able to say 'print 2 + 2' in Java and expect to get 4. This  
looseness is very much part of what makes PHP so easy to get into -  
if you really want these kind of features, you can just use Java  
instead!


Another point is that exception handling (another PHP5 feature) is  
next to useless without type hinting, so they HAD to implement it for  
objects so that catch clauses could work properly.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] time()

2005-07-29 Thread Marcus Bointon
On 29 Jul 2005, at 08:37, [EMAIL PROTECTED]  
[EMAIL PROTECTED] wrote:


I have the date when users registered stored in the database using  
time() function format.


Hm. I hope this means you're storing it as a TimeStamp format, or  
better, DateTime, and not as a simple integer field.


I have to search for users that are registered this week, this  
month and this year. How can i do that? I mean how can i found the  
beginning of this week?  Or the beginning of this month?


If you are storing it as a DateTime field, MySQL has loads of date  
related functions for doing this, and it's more efficient to do it  
using MySQL's functions that the equivalent in PHP. Take a look here:  
http://dev.mysql.com/doc/mysql/en/date-and-time-types.html and http:// 
dev.mysql.com/doc/mysql/en/date-and-time-functions.html


You can do the calculations in PHP. For example, to find the first  
day of this month as a timestamp:


$first = strtotime(date('Y-m-01'));

strtotime has some wonderful functionality - you can ask for dates  
like 'next week' 'last year' 'yesterday -1 week'.


To format a timestamp into a MySQL-compatible DateTime string, use:

$datetime = date('Y-m-d h:i:s', $timestamp);

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Multipage form redux

2005-07-28 Thread Marcus Bointon

On 27 Jul 2005, at 21:22, Jack Jackson wrote:


Right. Except I would rather have it working in a session because I  
specifically do not want to have the form sending $_POST data back  
and forth to the browser six times for several reasons. SO I'd like to


Page1 // User enters first batch of data, presses SUBMIT at bottom.  
Data is cleaned and written to SESSION, user passed to Page2


repeat as necessary to last page. At last page, process and error  
check newest input, then commit it, plus all previously stored  
session info to db.




As has also been said, Javascript can do this really nicely. The best  
example I've seen of this is in Mambo's (a popular PHP CMS) admin  
interface. It uses a tabbed multi-page form with client-side  
validation. It's really just one big page, so if the user has JS  
turned off, they will get one big form with no client-side  
validation, but it will still work. It's a really elegant way of  
working. It doesn't require any server interaction between pages -  
nothing is submitted until the form is complete.


See here for a howto: http://www.devx.com/webdev/Article/10483/1763/ 
page/1


Admittedly this approach doesn't easily allow to you abandon and  
resume later (unless you get clever with JS and cookies).


For keeping data in a session, you could combine this approach with  
Ajax: http://particletree.com/features/smart-validation-with-ajax


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Class constants

2005-07-28 Thread Marcus Bointon
I'm not sure if this is a bug or a feature, but it seems you can't  
use class constants to set default values for class properties. You  
can, however, use them for default values for method params, e.g.:


class foo {}
  const BAR = 100;
  private $thing = self::BAR;
  function wibble($a = self::BAR) {
echo $a;
  }
}

In this case $this-thing will be undefined, but wibble() will get  
the correct default value for $a.


Comments?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] function with argument of type array

2005-07-28 Thread Marcus Bointon

On 28 Jul 2005, at 12:07, André Medeiros wrote:


On Thu, 2005-07-28 at 11:08 +0200, marc serra wrote:


Hi, i want to know if it is possible to create a function and declare
that one of its arguments is array type.

In fact i want to do something like this

function test(String $litteral, array $foo){


There is no way to do that. What you _CAN_ do, to ensure you're  
getting

an array is:


There IS a way to do exactly this. It's called type hinting and it's  
a PHP 5 feature:


http://www.php.net/manual/en/language.oop5.typehinting.php

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Multipage form redux

2005-07-28 Thread Marcus Bointon

On 28 Jul 2005, at 14:13, Mark Rees wrote:


Rolling your own session management tool, whilst undoubtedly fun and
satisfying, is hardly an appropriate solution to this type of  
enquiry, which
is apparently from someone taking their first steps in web  
development.


Unsurprisingly, this is a situation that has been encountered many  
times before, and there are off-the-shelf solutions. ADOdb has a  
really nice session manager: http://phplens.com/lens/adodb/docs- 
session.htm
Database-backed sessions are particularly useful if you have multiple  
redundant web servers as successive hits within a session may go to  
different servers, so file- or memory-based sessions are not much use.


Despite this, I also suspect that sessions may not be the way to go.  
User authentication and management is not a synonym for sessions.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Calling methods in returned SOAP objects

2005-07-27 Thread Marcus Bointon
I'm successfully calling SOAP functions via a WSDL interface using  
PHP5, but sometimes the functions return things that are complex  
objects with methods as well as attributes. For example, the  
interface I'm using has a query function which returns an array, but  
it also has a function called IsDone() which can be called to find  
out if this is the last page of results (it returns records in batches).


It goes like this:

?php
require_once 'MyClient.class.php';

$mc = new MyClient();
$mc-dologin('id', 'pass');
try {
$res = $mc-query(array('queryString' = 'select Field from  
Table'));

$alldone = $res-isDone();
} catch (SoapFault $f) {
print 'Caught Exception: '. $f-faultstring. \n;
var_dump($mc);
}
?

You can see that $res is the result returned from the query, and it  
is presented as a stdClass object with results stored in an array  
property. However, when I try to call $res-IsDone(), it fails to work:


PHP Fatal error:  Call to undefined method stdClass::isDone()

I have some example code in Java for the same WSDL that makes it look  
very simple:


...
queryResult = binding.query(select Field from Table);
if (queryResult.isDone()) {
...

How on earth do I do that in PHP? I don't think that creating PHP  
classes and using classmap will help (it just moves the problem), at  
least partly because this is a dynamic WSDL that is subject to change.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] iconv trouble on OS X

2005-07-21 Thread Marcus Bointon
I wrote this question then found out where the problem was, so this  
is just for the archives...


==

I've compiled PHP 5.0.4 successfully on OS X 10.4.2, but I'm getting  
a weird problem with iconv. I specified it in my configure line:


--with-iconv

and it seems to pick it up ok while configuring:

checking for iconv support... yes
checking for libiconv in -liconv... yes
checking if iconv is Konstantin Chuguev's... no
checking if iconv supports errno... yes

It builds OK too. php thinks that the iconv extension is there:

 php -m|grep iconv
iconv

The entry in phpinfo() is rather suspicious:

iconv support = enabled
iconv implementation = unknown
iconv library version = unknown

Then in one script I get:

Fatal error: Call to undefined function iconv()

and function_exists('iconv') returns false.

I've also tried specifying --with-iconv=/sw (i.e. using  
libiconv-1.9.2-11 from fink), but I get the same results.




The solution lies in the user notes for iconv() where someone mentions:

elk at NOSPAMmodel-fx dot com
26-Jul-2002 04:07
If you use the libiconv library instead of the libc's iconv support,  
don't forget to use libiconv() instead of iconv()


And it really is as simple as that - just substitute libiconv() for  
iconv() - it seems that libiconv is the default on OS X. I think this  
is a terrible implementation (clearly PHP itself is confused by it, 3  
years on from this note) and I've no idea why it was done that way,  
but now at least someone can find out easily.


Marcus

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



Re: [PHP] Re: Tracking a mobile phone

2005-07-20 Thread Marcus Bointon

On 18 Jul 2005, at 20:56, Sebastian wrote:


The phone would have to have GPS capabilities..


Not true. The network knows what cell the phone is in(and cells are  
pretty small in cities), and it knows where the cell is. This is the  
mechanism that's used for location dependent services (especially  
directions and local maps) that are currently being pushed in the UK.


Whether you can get access to that information is another matter,  
especially internationally.


Marcus

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



[PHP] Overriding __soapCall

2005-07-14 Thread Marcus Bointon
I'm working on a soap client in PHP5, which I'm building by  
subclassing the built-in SoapClient class. However, it seems my  
overridden __soapCall method is never being called. My class looks  
something like this:


class myClient extends SoapClient {
public function __construct($wsdl = 'http://www.example.com/ 
my.wsdl', $options = NULL) {

if (!is_array($options))
$options = array('soap_version'  = SOAP_1_1, 'trace' =  
true, 'exceptions' = true);

parent::__construct($wsdl, $options);
}
public function __soapCall($function_name, $arguments = array(),  
$options = array(), $input_headers = NULL, $output_headers = array()) {

echo doing __soapCall\n;
return parent::__soapCall($function_name, $arguments,  
$options, $input_headers, $output_headers);

}
}

The constructor works fine. As you can see __soapCall does nothing  
but pass through the call to the parent, but it's just not being  
called. I've found various references to overriding the __call  
function (which is now completely obsolete as it clashes with a magic  
method) for the same kind of reason that I need to. So, it seems as  
if __soapCall is NOT called internally when calling a WSDL function,  
so if my client  has a login function:


$sc = new myClient();
$sc-login(array('username' = 'abc', 'password' = 'xyz'));

but this does not seem to go via the internal __soapCall function,  
thus denying me the ability to tweak the request on its way through.  
If I call it manually (i.e. non-WSDL way), something like:


$sc-__soapCall('login', array('username' = 'abc', 'password' =  
'xyz'));


then it works, but in that simple gesture I've lost most of the WSDL  
advantage.


What am I supposed to do?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Overriding __soapCall

2005-07-14 Thread Marcus Bointon

On 14 Jul 2005, at 16:07, Marcus Bointon wrote:

I've found various references to overriding the __call function  
(which is now completely obsolete as it clashes with a magic  
method) for the same kind of reason that I need to. So, it seems as  
if __soapCall is NOT called internally when calling a WSDL function


Answering my own question - __soapCall is not called internally, but  
you can force it by using __call (that is the magic method, not the  
obsolete __call function in SoapClient) by adding this function to  
the class:


function __call($function, $args) {
return $this-__soapCall($function, $args, null);
}

This means that I can finally get to pass stuff though my own  
__soapCall method, though I have the feeling that it may prevent me  
doing other stuff later on (I'm not normally relying on __call  
functionality).


Phew.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Compilation trouble on OS X

2005-06-13 Thread Marcus Bointon

On 12 Jun 2005, at 04:17, Richard Lynch wrote:


I vaguely recall an issue with mb_* where people saw this nifty new
feature and turned it on having no idea what it was, and, well, they
didn't really want that feature turned on at all...

This could be the same thing.

Or not.

Try ./configure --without-mbstring


Unfortunately I'm deliberately enabling mbstring because I need  
multibyte string support, along with mbregex... If I could live  
without these extensions I wouldn't need to recompile.


I just tried compiling on a clean install of 10.4, with a clean  
install of fink (I'm using some fink packages like apache2, JPEG,  
PNG, etc) and I'm still getting the ld problem I mentioned. Think I  
may have to report it as a bug and see what comes of that.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Compilation trouble on OS X

2005-06-13 Thread Marcus Bointon

On 13 Jun 2005, at 10:52, Marcus Bointon wrote:

I just tried compiling on a clean install of 10.4, with a clean  
install of fink (I'm using some fink packages like apache2, JPEG,  
PNG, etc) and I'm still getting the ld problem I mentioned. Think I  
may have to report it as a bug and see what comes of that.


A little perseverance always helps... I went through my configure  
command and removed a few possibly obsolete directives. I then ran  
into a dependency on gdbm that I can't explain, but after adding that  
in, I'm happy to report that it now works. For the record, here's my  
working config while building PHP 5.0.4 on OS X 10.4.1 as an  
apache2handler using fink libraries, also notable is that it also  
enables both mysql and mysqli extensions simultaneously:


'./configure' \
'--disable-overload' \
'--enable-bcmath' \
'--enable-calendar' \
'--enable-dba' \
'--enable-exif' \
'--enable-ftp' \
'--enable-gd-imgstrttf' \
'--enable-gd-native-ttf' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-mcal' \
'--enable-pcntl' \
'--enable-shmop' \
'--enable-soap' \
'--enable-sockets' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--enable-track-vars' \
'--enable-wddx' \
'--sysconfdir=/etc' \
'--with-apxs2=/sw/sbin/apxs' \
'--with-bz2' \
'--with-config-file-path=/etc' \
'--with-config-file-scan-dir=/etc/php.d' \
'--with-curl' \
'--with-dom=/usr' \
'--with-freetype2-dir=/sw' \
'--with-gd' \
'--with-gdbm=/sw' \
'--with-gettext=/sw' \
'--with-iconv' \
'--with-imap-ssl=/sw' \
'--with-jpeg-dir=/sw' \
'--with-png-dir=/sw' \
'--with-ldap' \
'--with-mcrypt=/sw' \
'--with-mhash=/sw' \
'--with-mysql=/usr/local/mysql' \
'--with-mysqli=/usr/local/mysql/bin/mysql_config' \
'--with-openssl' \
'--with-pcre' \
'--with-pear' \
'--with-png' \
'--with-ttf' \
'--with-xml' \
'--with-xsl' \
'--with-zlib' \
'--without-oci8'

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Making a page loop with header('Location: ...

2005-06-10 Thread Marcus Bointon

On 10 Jun 2005, at 00:36, Joe Harman wrote:


I've ran into a little bit of a snag with php execution time... so, i
need to execute the page a few times so that I can split the operation
up into multiple parts... my other option would be to make a
javascript reload


A more elegant solution is to split the process so that you can  
handle it asynchronously. Create a server-side process that does your  
long operation, then make your page refresh monitor it, using a  
simple page refresh. This way you completely avoid timeout issues -  
you can have operations that go on continuously for days at a time.  
This article I wrote might help:


http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20977409.html

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Beautiful HTML Invoice - Prints like crap! I need somesuggestions!

2005-06-09 Thread Marcus Bointon

On 7 Jun 2005, at 23:46, Chris Martin wrote:

Is a simple CSS print stylesheet out of the question?
If the site is marked up properly, this should be trivial, and would
be much easier/more efficient.


CSS is definitely the way to go. Here are some good articles:

http://www.alistapart.com/articles/printyourway/
http://www.alistapart.com/articles/goingtoprint/

Marcus

--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



[PHP] Compilation trouble on OS X

2005-06-09 Thread Marcus Bointon
I've been beating my head against this  - I've done this so many  
times on BSD and Linux but I just can't get PHP 5.0.4 to compile on  
OS X. Even the simplest case:


./configure
make

fails with:

/usr/bin/ld: Undefined symbols:
_mbstring_globals
_php_mb_encoding_translation
_php_mb_gpc_encoding_converter
_php_mb_gpc_encoding_detector
_php_mb_gpc_mbchar_bytes
_php_mb_strrchr
_php_ob_gzhandler_check
collect2: ld returned 1 exit status
make: *** [sapi/cgi/php] Error 1

I'm running 10.4.1 on a dual G4.

I've also built a much more complex configuration (why I need to do  
this) that configures OK, but gives me this on make:


/usr/bin/ld: unknown flag: -export-symbols
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1

OS X's ld command definitely lacks this option, so I removed  
references to it from the configure script, and just got some  
different errors.


I have an up to date fink installed and I'm pulling in some stuff  
from there (jpeg, freetype etc), and my CFLAGS contains:


DBIND_8_COMPAT=1 -DEAPI -O3 -mcpu=G4 -mtune=G4 -I/sw/include

(I've tried emptying it too, same error)

I can't use the Entropy binaries as they're missing some extensions I  
need. There are no bugs posted on the PHP tracker that match these  
errors, so it's clearly not a common problem.


Any ideas what might be broken, and how I might fix it?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Compilation trouble on OS X

2005-06-09 Thread Marcus Bointon

On 9 Jun 2005, at 15:46, John DeSoi wrote:

Do you have the latest XCode installed? I think there was a recent  
update for OS X 10.4. I did not have any problems compiling PHP  
5.0.4 with OS X 10.3, but I have not tried 10.4 yet.


I do have XCode 2.1, but I don't think it has anything to do with  
this. PHP's build system is completely independent of XCode. PHP uses  
normal Unix-type tools such as gcc, make, ld, libtool, autoconf etc.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] Compilation trouble on OS X

2005-06-09 Thread Marcus Bointon

On 9 Jun 2005, at 18:11, Brent Baisley wrote:

I'm pretty sure you have to install the developer tools in order to  
get the gcc compiler installed. So while you don't need XCode to  
compile, you do need the developer tools, which is almost  
synonymous with XCode.


Of course I have the developer tools installed - I wouldn't even be  
able to attempt a compile without them. XCode is an IDE - it provides  
project management and a nice GUI for lower level tools, however, it  
is squarely targeted at development of OS X applications that are set  
up as XCode projects, which does not include PHP. Bear in mind that  
almost none of the thousands of open source projects available via  
sources like fink have anything to do with XCode - they're all  
designed for a standard unix-style build system using the tools I  
mentioned.


Doesn't 10.4 ship with gcc 4? I know I read about some bugs and  
problem with gcc 4, some specifically related to PPC chips. Do you  
know if you are compiling using 3.3 or 4.0?


I'm using the standard system gcc 4.0.0, but this is a problem with  
the parameters (defined in the PHP configure script) passed to ld, so  
strictly speaking this is a linking rather than a compiling problem  
(i.e. the problem occurs after gcc has finished successfully). It  
seems that the OS X ld has different options to the GNU or BSD  
implementations, so I guess I'm really after someone that knows ld  
well enough.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] PHP 5 Question about OO

2005-06-02 Thread Marcus Bointon

On 2 Jun 2005, at 03:00, Richard Lynch wrote:


Maybe I'm being dumb, but how can an object's __autoload function get
called when the object class definition hasn't been loaded, and  
that's why

you're calling __autoload in the first place...


It wouldn't solve everything, but it would help. It solves the case  
where you have a class library that's quite heavily interconnected,  
and member functions instantiate other classes in that library (a  
common arrangement in my experience). By having an __autoload method,  
you get to at least partly avoid global handler clashes by having one  
that is specific to that library (it would work well in PEAR). If it  
is in a base class, then you are safe in the knowledge that any class  
can find any other in the same library, without tripping over anyone  
else's arrangements. You would still have to deal with the problem of  
finding the first class (which a global handler may help, subject to  
the issues that you've already raised), but once that's done, the  
problem is over. I don't see why they named it __autoload - the __  
prefix is usually reserved for special purpose methods, not global  
functions. Just plain 'autoload' in a global context is not really  
anything wildly different in style to say ini_set or error_reporting.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] PHP 5 Question about OO

2005-06-02 Thread Marcus Bointon

On 2 Jun 2005, at 11:56, Colin Ross wrote:

The way I see it, you are gonna be spending quite a bit of time  
writing all those lines of code for the class, what is bad about  
another requiring the file each time?


Huh? Writing a 1-line function in a base class means that I would  
never have to write another require anywhere in my library (other to  
include the base class of course, which could conceivably be picked  
up by a global autoload anyway). Each of my 50-odd classes probably  
talks to 5 other classes in the library, giving a net saving of 250  
lines. How is that bad? (I am talking hypothetically anyway as we  
don't have autoload methods at present).


This thread is meant to be about how to improve automatic include  
file location - saying not to try to do it at all is not very helpful.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] [Files suffix] .inc.php files

2005-06-01 Thread Marcus Bointon

On 1 Jun 2005, at 06:22, Richard Lynch wrote:

You've got files that people can get executed *COMPLETELY* out of  
context,
that *NOBODY* even though about being executed out of context, much  
less

*TESTED* in any kind of QA process!

I can surf to http://example.com/admin.inc and who knows what will  
happen
if that PHP code in there gets executed without all the code you  
expected

to be executed before that code?


There is one simple habit that can mitigate this issue, and it's one  
I see very often: make your .inc.php and .class.php files do nothing.  
If you .inc files contain only function and constant definitions, and  
your .class files contain only class definitions, then nothing will  
happen when you run them - a bunch of functions or a class will get  
defined, but if nothing is run, they will just be forgotten. This  
route has a major advantage when it comes to deployment - you can  
just stick all your files in one place, and it will work without  
risk. Another simple approach is to put all your included files in a  
directory that contains a .htaccess file to prevent direct access to  
them. They can still be included from your PHP scripts.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] PHP 5 Question about OO

2005-06-01 Thread Marcus Bointon

On 1 Jun 2005, at 09:01, janbro wrote:


require (Class2.php);
class Class1{
private function ... {
$refClass2 = new Class2;
}
}

Now my question, is it possible to skip that require/ include part? In
Java you don't need that, as class and file names are identical.


PHP doesn't have this luxury - people can call files whatever they  
like. However, PHP5 does have a nice feature to deal with this. In  
your class1 class, create a function called __autoload like this:


function __autoload($class_name) {
   require_once $class_name . '.php';
}

In this case when you ask for a new class2 and you've not required it  
before, it will automatically call __autoload with $class_name set to  
'Class2', which then requires the class file according to the pattern  
used in the function, in this case 'Class2.php'. Note that while PHP  
is not case sensitive to class names, the file system you're on  
probably is, so keep your case consistent throughout.


Docs are here: http://www.php.net/manual/en/language.oop5.autoload.php

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] PHP 5 Question about OO

2005-06-01 Thread Marcus Bointon

On 1 Jun 2005, at 11:38, Jochem Maas wrote:

all true, now imagine that you install a couple of 3rdparty php5  
'packages'
and they all define __autoload() - ain't gonna work! which is why  
there has been
discussion on internals regarding the possibility of use a handler- 
function stack
for autoloading (in the same way that you can register a stack of  
input/output
filter-function)... something to keep an eye on in case things  
change :-)


I've run into this one. One way that would work for me (and initially  
it's how I assumed it worked) is for __autoload to be a standard  
class method like __construct, so that a class would attempt to run  
its own autoloader before breaking out to the global function namespace.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



Re: [PHP] xml

2005-05-31 Thread Marcus Bointon

On 27 May 2005, at 14:16, Andy Pieters wrote:

I recently decided to switch to xml for the configuration of our  
programs.


I am now looking for a good way to handle that xml data.

Basically, what I am looking for is a functionality where I say

Get tag x with attribute1=y, attribute2=z,..., read its contents  
and put it in

an associative array.


You have described exactly what the pear config package does: http:// 
pear.php.net/package/config/


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



  1   2   >