php-general Digest 24 Sep 2006 16:06:16 -0000 Issue 4365

Topics (messages 242163 through 242168):

Re: Object to array conversion oddity
        242163 by: Robert Cummings
        242166 by: Marcus Bointon
        242167 by: Marcus Bointon

Re: php/css and .htaccess [SOLVED]
        242164 by: Richard Lynch

Re: reading urlencoded data from POST
        242165 by: Richard Lynch

array_sum($result)=100
        242168 by: Ahmad Al-Twaijiry

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sat, 2006-09-23 at 22:35 +0100, Marcus Bointon wrote:
> 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.

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

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
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/

--- End Message ---
--- Begin Message ---
On 24 Sep 2006, at 01:09, Robert Cummings wrote:

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

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

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

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

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

--- End Message ---
--- Begin Message ---
On Sat, September 23, 2006 10:06 am, tedd wrote:
> I am sure that with a little browser sniffing via php and taking

Browser-sniffing is the unreliable part.

> compliant (hack-less) code, one could get the code to adapt to the
> browser. In other words, this would present an option for all css
> coders to ignore all hacks. Just add a couple of lines to their css
> code (i.e., header) and change their .htacess file-- and after that,
> they would just write compliant code and the php would make the
> changes to match the browser -- why hasn't that been done?
>
> It's not simple, but it certainly is not impossible.

I generally just don't do the CSS hacks. -- If I have to hack the CSS,
then that defeats the purpose of using CSS.

Change the design to avoid the hack. :-;

That said, sure, it would be a fine thing to have browser-specific CSS
spit out by PHP in your CSS, if you have somebody competent enough to
do the CSS and not screw up the PHP...

Rather defeats the purpose of separation of Church and State, but
there ya go...

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

--- End Message ---
--- Begin Message ---
$_POST is useful for FORM data -- it urldecodes the data, and assumes
it's something somebody would actually type into a FORM.  This would
be what 99.9% of websites need and want.

$HTTP_RAW_POST_DATA gives you ALL the raw encoded data to parse as you
see fit.  This covers the rest of the needs.

If you need something even more arcane than either of those, run your
own service on your own socket.

On Sat, September 23, 2006 3:35 am, Marek 'MMx' Ludha wrote:
> Accessing $HTTP_RAW_POST_DATA is similar to reading php://input which
> I mentioned in my previous email.
> I am not quite sure what is $_POST useful for. It is intended for
> reading urlencoded data which it does only in special cases (no \0 or
> \5C chars) and everyone has to parse it himself. Did I miss something?
>
> --
> Marek 'MMx' Ludha
>
> On 9/23/06, Richard Lynch <[EMAIL PROTECTED]> wrote:
>>
>>
>> Search php.net for RAW_HTTP_POST or somesuch.
>>
>> It's there for ya.
>>
>>
>>
>> --
>> Like Music?
>> http://l-i-e.com/artists.htm
>>
>>
>>
>


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

--- End Message ---
--- Begin Message ---
Hi everyone

I have array of numbers and I want to get out of it a list of numbers
that if I sum them it will be 100, here is my list (for example ) :

$list = array(10,20,10,10,30,50,33,110,381,338,20,11,200,100);


I want the result to be :

$result = array( 10,20,10,10,50);

as you can see in the array $result , if we array_sum($result) the
result will be 100.

is they any algorithm to do this ?

--- End Message ---

Reply via email to