[PHP] Creating a PHP5 RPM

2004-07-27 Thread Marcus Bointon
I normally compile PHP straight from the regular source, however, this means
that RPM loses track of what PHP version is installed on RedHat Linux (EL3),
causing dependency and version mismatch problems. So it appears that I need
to build an RPM from the normal source, then install it with RPM. However, I
have no idea how to do this - can anyone give me some pointers? Is it as
simple as adding a configure switch like --build-rpm?

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



[PHP] mysql and mysqli

2004-07-27 Thread Marcus Bointon
I've got mysql 4.1.13 installed on RH EL 3 and I'm trying to build PHP5
against it with both mysql and mysqli extensions. It's quite happy to config
and make with --with-mysql=/usr/local or --with-mysqli, but if I specify
them both together (in either order), I get thousands of errors like this:

/usr/lib/mysql/libmysqlclient.a(my_static.o)(.data+0x6b4): multiple
definition of `my_default_record_cache_size'
/usr/lib/mysql/libmysqlclient.a(my_static.o)(.data+0x6b4): first defined
here

Finally ending with:

collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1

I installed all of mysql from official RPMs, except for devel and shared
modules which I compiled from the source RPM (These 4.1.13 binary RPMs are
hard-wired to OpenSSL 0.9.6 so you can't use them on any recent OS).

Any ideas to 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



[PHP] PHP 5 - $_REQUEST undefined???

2004-08-08 Thread Marcus Bointon
I'm getting errors like this:

Notice: Undefined variable: _REQUEST in /var/www/html/index.php on line 57

This is truly weird - why on earth would this superglobal be undefined? (and
there is no unset($_REQUEST) lurking!) As far as I'm aware, there isn't even
an ini option to turn it off.

I'm in the process of upgrading from PHP4 to 5, and this script works ok in
4 - the error is just in 5.

Any 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] oop too slow

2004-08-19 Thread Marcus Bointon
on 19/8/04 9:49, Krzysztof Gorzelak at [EMAIL PROTECTED] wrote:

> Hi
> I'm trying my new php5 script, but it takes about 1.2s to generate my page.
> That is, how my oop model looks like :
> 
> [category]
>   |||
> [photo]  [desc]   [products]
> 
> 
> [products]
> |
> [product]
> |||
> [photo] [desc] [keys]
> 
> 
> [keys]
> |
> [key]
> |
> [values]
> |
> [value]
> 
>   Each object gets data from mysql by itself. The generation time of 1
> category [30 products, 10 keys, 5 values ~= 300 mysql queries] takes as I
> said more than a 1s (on quite fast machine). How can this model be improved?
> Do I create too many objects ? What are the oop solutions for such problem ?

This is something that I've wrestled with too. If you make each item you
deal with a clean, self-sufficient object, with self-storage, data hiding
etc, it is inevitable that you run into this problem. It is a symptom of a
fundamental clash between Relational DB and OO points of view. The only
trick I have found to work around it that is OO-clean is to use factory
methods or objects that create multiple objects from a single DB query, so
as well as having a 'get' method that populates an object from a DB, make
another means of creating an object from local data that has been obtained
from a larger query that returned sufficient values to populate multiple
items.

> I also use an extra table to create many-to-many relation betwean a product
> and a key. Is this the only way in mysql ?
> 
> [product]
> |
> [product_id, key_id]
>   |
>   [key]

Yes, that's the correct way to represent a M:M relation in a relational DB.
The join table is an artefact of a relational model, rather than an OO one,
so the answer is to hide the existence of this table within the objects at
either end - so have product and key objects, but not product_key objects.
Each object should have a method that retrieves instances of all the related
objects of the other kind. This is really a different manifestation of the
first problem.

Ultimately the trick is to create separate factory objects or higher-level
methods inside the existing objects that can create multiple instances from
a single database query. Having said that, it's difficult to spot the best
places to do this. For example, you might normally create multiple product
objects from an array of database IDs like so:

foreach($productids as $id)
$products[] = new product($id);

You can see that this would cause a query for each instantiation.

With a product factory class, you might do this instead:

$products = product_factory::get($productids);

Which achieves the same result, but using only a single DB query (hidden
inside the factory class, which does NOT call the product class in the same
way!). The next problem is keeping your product_factory and product classes
in sync - I'm sure there must be a nice pattern to deal with that somewhere.

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] Mac OS X compilation problem

2005-04-27 Thread Marcus Bointon
In the past I've had success compiling PHP4 on OS X. However, now I'm 
trying to get PHP5 working and not having much luck. I'm getting 
configure to work, and make goes ok until the final linking stage at 
which point I get this error:

ld: unknown flag: -export-symbols
make: *** [libs/libphp5.bundle] Error 1
It seems that that flag must be set in a make file somewhere (it's not 
in my environment), and it's certainly not documented in the OS X ld 
man pages.

Not sure if it makes any difference, but most of the external modules 
that PHP uses are built from fink. I need some modules that are not 
supported in any of the pre-built fink PHP5 packages, and I'm used to 
compiling it without difficulty on Linux and OpenBSD.

Anyone else run into this or have any idea 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] Re: Valid email address syntax script?

2005-05-04 Thread Marcus Bointon
On 3 May 2005, at 19:18, Matthew Weier O'Phinney wrote:
* Jm <[EMAIL PROTECTED]>:
Does anyone have a nice email address syntax checking script they'd
like to share? Regular expression-based anyone? TIA.
I use the following regex:
preg_match('/[EMAIL PROTECTED]@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email)
I believe I got it out of the PHP Cookbook, by David Sklar, but I  
can't
remember for certain. It's not 100% accurate, but I rarely have
complaints from users whose emails don't validate.
I've used this one quite heavily. It doesn't go as far as checking  
TLDs, but it's quite tight on RFC2822 and allows things like numeric  
addresses:

preg_match('/^(?:[\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])\]))$/', $email);

I got it from here - they have some more and some commercial products  
that go further:

http://www.hexillion.com/samples/#Regex
Marcus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Seeking decent domain registrar

2005-05-12 Thread Marcus Bointon
Somewhat OT - I've had almost entirely poor experiences with domain  
registrars, so I'm looking for recommendations. I need:

.com, .net, .org domains (easy enough!)
.co.uk support
Multilingual domain support e.g. café.com
Online control of DNS server assignment
Specification of external DNS at registration time (so you don't have  
to change it unnecessarily afterwards)
Multiple admin accounts (I run domains for other people in their  
names and I want to keep them separate)
Don't need any forwarding, web hosting, email or anything beyond  
registration
Low-cost would help of course!

I've been googling for registrars, but as yet I've not found anyone  
that offers all this. Can anyone recommend a registrar that has a  
clue and a decent web interface?

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] Seeking decent domain registrar

2005-05-13 Thread Marcus Bointon
On 13 May 2005, at 01:11, Richard Lynch wrote:
On Thu, May 12, 2005 3:40 am, Marcus Bointon said:
Multilingual domain support e.g. café.com
Er.
Maybe they changed the rules, but I don't think that's a valid  
domain name
AT ALL.

So maybe the reason you are having trouble is you are looking for
something that cannot exist...
They did "change the rules" starting in November 2000, with RFCs  
(3454, 3490, 3491, 3492) finalised in 2003. See http:// 
www.verisign.com/products-services/naming-and-directory-services/ 
naming-services/internationalized-domain-names/index.html This page  
may be of interest too: http://www.imc.org/idna/. Also, have you  
tried going to www.café.com? It works just fine for me (if you're  
using an antique browser like IE6 it may not work, though verisign  
have a free plugin to enable it). http://www.1stdomain.net/ does  
international registrations (though does not handle .co.uk domains).  
From a PHP point of view, http://pear.php.net/package/Net_IDNA/  
what's needed.

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] Seeking decent domain registrar

2005-05-16 Thread Marcus Bointon
On 14 May 2005, at 07:53, Richard Lynch wrote:
For the record, no I haven't tried to go to that URL, because I  
don't even
know how to type that symbol.
Ah. I don't think you use a Mac ;^) MacOS (9 and X) has a wonderful  
system for typing any accented characters very easily (from an  
English keyboard) that can be explained and easily remembered in  
about 10 seconds. One simple technique enables me to type  
áéíóúäëïöüàèìòùöâêîôûñõ without having to remember large numbers of  
keystrokes or codes.

If I did know how to type that non-ASCII symbol, I don't quite  
understand
which of the umpteen "extended" character sets is going to get used  
by all
the DNS machines, so I'd be kind of surprised if it worked, but,  
hey, if
it all works and everybody is happy, it's all good.
It's easy - it's all unicode mapped into ASCII so it works  
transparently with DNS systems, who don't have to think in anything  
other than plain ASCII. It's up to individual applications to map the  
presentational aspect - raw mappings will work in all applications -  
try going to www.xn--caf-dma.com (the punycode rendering of  
www.café.com).

I feel sorry for anybody who has such a domain name, however, as it's
going to be a real bear to get it listed/indexed correctly by search
engines, I would guess.  Maybe not.  Maybe all the search engines  
are all
ready for the non-ASCII domain names.  [shrug]

I certainly understand that the DNS space is now much bigger, and much
nicer for non-English (or, perhaps more accurately,
non-ASCII/Roman-alphabet) websites who can now get their domain  
name in
their own native language.  And I think that's really great.

But it's sure gonna make it hard for a lot of users to figure out  
how to
get there...
Bear in mind that in languages that DO make use of accented (or just  
plain different) characters, they are utterly normal and everyday.  
Someone who considers "cafe" to be misspelled relative to "café" will  
find it EASIER to use the correct version than to have to translate  
into the English "dumbing down" of their language - that you might  
find it harder is not a consideration.

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] PHP5 binaries

2005-05-20 Thread Marcus Bointon
It seems that none of the current major Linux distros provide PHP5  
binary installation packages. By major I mean, RedHat, Fedora (it  
will be in F4 when released), Mandriva, Debian, Ubuntu, possibly  
others. Seriously, none have standard PHP5 packages, even optional  
ones. Does no-one use PHP5??? It's not exactly bleeding edge, having  
made a final release nearly a year ago.

I'm trying to set up an automatable installation system for such  
evident rarities as RedHat Enterprise Linux 4, and I just can't find  
anything workable. Even php4 binaries are rare (especially ones with  
flexible options including things like pcntl). Perl is massively  
supported, with binaries for hundreds of extensions widely available.  
Why does PHP get such second-rate treatment? Is it particularly hard  
to build packages for?

I'm quite used to building PHP5 from source, but it's not the most  
elegant way of deploying things. The PHP download page says "Most  
Linux distributions come with PHP these days, so if you do not want  
to compile your own, go to your distribution's download site.", but  
that's no use if no-one actually provides them for current releases.

Even in the various rpm repositories PHP5 is a rare beast - for  
example rpmforge's members don't include it. rpmbone provides some  
very basic rpms, but they suffer from dependency problems (even when  
accessed via apt-get).

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


[PHP] Preventing static method calls in PHP4

2004-07-21 Thread Marcus Bointon
If I want to prevent a method from being called statically in PHP4, how can
I do it? So far I've tried these techniques:

Anotstatic = true;
  }
  function dynamic() {
if (!isset($this) or !is_a($this, 'A') or !(isset($this->Anotstatic) and
$this->Anotstatic))
echo "Method called statically\n";
else
echo "dynamic-only function\n";
  }
  function test ()
  {
 A::dynamic();
  }
}

class B {
function test() {
  A::dynamic();
}
}

$a = new A();
$a->dynamic();
A::dynamic();
$b = new B;
$b->test();
$a->test();
?>

This works for the first 3 tests (so I'm getting there), but not the fourth,
that is a dynamic method being called statically from an instance of the
same class. Is there something I've missed that will allow me to intercept
this style of call?

I know that this problem goes away in PHP5, and that the setting of $this in
static calls from other instances is not a bug (though it's the root of this
problem)!

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] Zend Enc and 0T Q

2004-07-21 Thread Marcus Bointon
on 21/7/04 16:59, PHP Gen at [EMAIL PROTECTED] wrote:

> News to me, I thought each encryptor has its own
> "style" of encrypting the phpwill check up but I
> think thats true.

Mmcache says explicitly that its output is compatible with Zend encoder.
Also note that encryption is not the same as encoding.

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] Preventing static method calls in PHP4

2004-07-22 Thread Marcus Bointon
[repost, not sure if it worked last time]

If I want to prevent a method from being called statically in PHP4, how can
I do it? So far I've tried these techniques:

Anotstatic = true;
  }
  function dynamic() {
if (!isset($this) or !is_a($this, 'A') or !(isset($this->Anotstatic) and
$this->Anotstatic))
echo "Method called statically\n";
else
echo "dynamic-only function\n";
  }
  function test ()
  {
 A::dynamic();
  }
}

class B {
function test() {
  A::dynamic();
}
}

$a = new A();
$a->dynamic();
A::dynamic();
$b = new B;
$b->test();
$a->test();
?>

This works for the first 3 tests (so I'm getting there), but not the fourth,
that is a dynamic method being called statically from an instance of the
same class. Is there something I've missed that will allow me to intercept
this style of call?

I know that this problem goes away in PHP5, and that the setting of $this in
static calls from other instances is not a bug (though it's the root of this
problem)!

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: Preventing static method calls in PHP4

2004-07-22 Thread Marcus Bointon
on 22/7/04 10:49, Jason Barnett at [EMAIL PROTECTED] wrote:

> The easiest way I can think of to prevent static method calls is to use the
> $this pseudo variable in your method.  A method *cannot* be used statically if
> the method requires use of $this.

Unfortunately that doesn't work - it is exactly the case that fails in my
example. $this IS set in a static method that's called from any object
instance (even one of a different class), and it's a PHP feature, not a 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



Re: [PHP] run perl script with php

2004-07-22 Thread Marcus Bointon
on 22/7/04 10:42, Tassos T at [EMAIL PROTECTED] wrote:

> i faced a small problem i have a perl script but i want to execute that
> in a php script. unfortunately i cannot convert to php.

No problem, look at:

http://uk2.php.net/manual/en/function.system.php
http://uk2.php.net/manual/en/function.exec.php
http://uk2.php.net/manual/en/function.passthru.php

E.g. system('myperlscript.pl');

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: loop in horizontal direction (php-html)

2006-08-10 Thread Marcus Bointon

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


s don't need to be terminated with s


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



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



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



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:


NULLNULL

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


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



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



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



[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] $_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] strtotime time zone trouble

2005-01-18 Thread Marcus Bointon
How is this not a bug?

outputs:
2005-01-18 09:58:09 (correct)
2005-01-18 17:58:09 (incorrect)
The time zone correction is applied in the wrong direction. Does it in 
both current PHP 4 and 5.

Named time zones like these are supposedly deprecated, but the 
suggested alternative in the docs doesn't work at all:

print date('Y-m-d H:i:s', strtotime('now UTC-0800'))."\n";
1970-01-01 00:59:59
using 08:00 doesn't work either
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] strtotime time zone trouble

2005-01-18 Thread Marcus Bointon
On 18 Jan 2005, at 10:53, Tom wrote:
PST = UTC - 8, therefore if you ask for strtotime in PST it will give 
you  now + 8. This is standard in most languages, you are just reading 
the functionality back to front.
ie when you say strtotome('now PST'), what you are asking for is the 
current local time (UTC in your instance) given an input date in PST
OK, I see some logic in that - now how to work around it?
try
print date('Y-m-d H:i:s', strtotime('now') -0800)."\n";
That definitely won't work; -0800 will be interpreted as an octal 
value, but it's not a legal value. If it was interpreted as a decimal 
value, it would subtract 800 minutes, which is no use to anyone. 
Numeric offsets are supposed to work inside the strtotime string param, 
according to the docs.

Much of the point of using zone names rather than fixed numeric offsets 
is that it allows for correct daylight savings calculations (assuming 
that locale data is correct on the server).

Let me rephrase the question - how can I get the current time in a 
named time zone using strtotime and without using a numeric offset?

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



[PHP] Plugin systems

2005-05-31 Thread Marcus Bointon
I'm looking to build a plugin system for my web application. I'm  
going to need to handle multiple types of plugin. I know that many of  
them exist already, but I'm wanting something that's very object- 
clean and PHP5-aware. I was thinking about using multiple interface  
implementations, so that I could have a plugin that provides a  
particular kind of database access, provides a user interface for  
admin purposes, and a simple display unit perhaps for connection  
status. In this case I'd define a class like:


class mynewplugin extends pluginbase implements database, admin,  
display {

  //...
}

I would then be able to introspect (using class_implements etc) to  
find, for example, all plugins that implement database access. I  
could easily add more plugin types by adding more interface types.  
The overall benefit being that all kind of plugin are handled through  
a single mechanism.


Does this sound like a solid structure and mechanism?

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

2005-05-31 Thread Marcus Bointon

On 31 May 2005, at 09:58, Jochem Maas wrote:


Also I hear lots of good things about subversion (SVN), which is a
newer alternative for version control - some even say its better.


I can definitely vouch for Subversion. I'm using it for all my PHP  
stuff. I'd not used cvs a great deal, but I'd always found it awkward  
and svn is certainly easier.


The home page is here: http://subversion.tigris.org/ The  
documentation (an online O'Reilly book) is excellent. It's pretty  
easy to learn (shares most basic commands with cvs), and there are  
many helper apps to work with it, not least TortoiseSVN which looks  
and works just like TortoiseCVS. I'm on OSX with OpenBSD and Linux  
servers and it's been easy to get it working over HTTPS. There are  
some OSX clients (notably svnx), but I find that once you figure out  
the commands, the command line interface is very easy to work with.


Consensus seems to be that if you're just starting out in version  
control, go straight to svn so you can skip all the reasons that made  
them want an upgrade from cvs!


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

2005-05-31 Thread Marcus Bointon

On 31 May 2005, at 15:40, Bostjan Skufca @ domenca.com wrote:


is it possible to mount CVS/SVN repository as filesystem?


Yes and no. Both keep stuff as normal files, but often as diffs and  
BDB databases. You really need to go through the appropriate client  
interface to extract data from it meaningfully. Also, you don't  
normally work directly on the repository but on a locally checked out  
version. This is what makes concurrent edits possible. SVN is  
typically implemented as a WebDAV service (possibly using SSL for  
security), and you can simply mount the webdav point as you would any  
other webdav file system. I guess you could check out a version  
remotely, then mount that area via webdav. Not sure what you'd gain  
though.


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] Plugin systems

2005-05-31 Thread Marcus Bointon

On 31 May 2005, at 15:21, Jochem Maas wrote:

seems like alot of spreadout functionality to be putting it in a  
single

class (maybe I'm not seeing your example in the proper light).


That's possible, and I would only be able to implement a single  
plugin class within any given file (assuming simplistic namespacing).  
However, I do think that it's quite likely that any single plugin  
will likely only implement one or two interfaces so it should not get  
too messy. Think about photoshop here - you can just chuck plugins in  
the plugins folder, and they are all handled in the same way,  
regardless of whether they add file importing, exporting or image  
processing functions, or even all three at once.



it sounds like lots of work, with the possibility that it will become
overengineered... which has the affect of:

1. making code slow (introspection and reflection are not the  
speediest parts of the engine!)

2. make seemingly simple things difficult because of all the hoops you
have created for yourself.


Built-ins are almost always faster than 'userland' PHP code, and it  
seems that this approach might hit quite a few sweet spots in that  
respect. There's no particular reason this should have any great  
impact on speed as it's not really any different to loading a bunch  
of classes (something which is massively improved with an accelerator  
anyway).


The plugin system needs to do several things:

* locate plugin files (just normal readdir calls)
* within located plugins, locate implementations of particular  
functionality (a simple call to class_implements)

* run preferred implementation

Smarty has quite a neat plugin mechanism, but it's quite limited in  
what it tries o do - for example there's no way you can directly  
build block, modifier and function plugins with identical  
functionality in a single file (though you could do it using a shared  
class and a bunch of includes - exactly the complexity I'm trying to  
avoid).


How might I achieve this without using these built-in functions, and  
why might it be faster and less complex?


There are some very complex plugin systems, such as the one recently  
added to MaxMediaManager which uses this model:


http://www.martinfowler.com/articles/injection.html#UsingAServiceLocator

but I'm wanting to keep things simpler.


but then there is nothing to suggest that you can't make it work
- the kind of thing you suggest doing is a good way of utilizing
the advantages of the object model.

I doubt it will be easy to write it well... but hey thats half the  
fun right?! :-)

by all means hit the list with all your tricky little php5 problems,
I for one will be on the look out for them :-)


I get the feeling that it will actually be quite simple to write -  
that's partly why I'm wondering what's wrong with it ;^)



1. what is the objective you wish to accomplish with such a 'system'?


The system I'm working on implements large chunks of functionality  
internally. I want to make it switchable so that I can reconfigure it  
to use external resources on a dynamic basis. My main aim is to build  
a kind of host environment and reimplement my internal functions as  
plugins so that all implementations of the functionality can share  
the same interfaces. Many applications are built this way - Apache  
and Dreamweaver MX spring to mind.


2. do you have a very strict definition of 'plugin'? (I have always  
found the

word rather woolly/inexact)


That's part of the point. With the mechanism I'm thinking of, I don't  
have to be too precise about what exactly a plugin might do - I only  
need to define the different plugin interfaces (which can be very  
strict) that it might conform to - implementation is wide open.


I'd welcome a discussion of plugin mechanisms generally...

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

2005-05-31 Thread Marcus Bointon

On 31 May 2005, at 17:57, Bostjan Skufca @ domenca.si wrote:

a. It would create a posibility to run application directly from  
CVS if http

server would have access to it


It doesn't work that way - there are almost no circumstances under  
which you would want to access the repository without going through a  
client. The only case I can think of is for backup. You can automate  
checkouts from your repository - Subversion provides scripting hooks  
to do exactly that kind of thing automatically. You can set up a  
trigger like 'whenever someone makes a commit to this branch, do a  
checkout to this directory'.


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



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



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

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



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



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



[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] 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] 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=
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



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



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 `è' and `î' are not entities in charset utf-8, use
`&egrave;' and `&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



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



[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] 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:




(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



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



  1   2   >