php-general Digest 1 Apr 2006 17:45:41 -0000 Issue 4047

Topics (messages 233040 through 233048):

Re: How to debug in CakePHP.
        233040 by: John Nichel

Re: preg_match
        233041 by: chris smith

Re: Overloading Limitation- Can Someone Confirm?
        233042 by: Jochem Maas

iconv returns blank string, not false
        233043 by: joseph
        233045 by: joseph

utf8_encode failes?
        233044 by: Merlin

PHP AJAX Framework - Suggestions Please
        233046 by: Andrei Verovski (aka MacGuru)
        233048 by: Greg Beaver

Re: MySQL close connection, what's the purpose?
        233047 by: tedd

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
chris smith wrote:
Hi everybody!
I use cake, I have an error, but I can't find where the error occurs.
Have any tools for debug?

Set up an error log. Edit your php.ini file and set:

log_errors = On

error_log = /path/to/logfile.log

then errors will get put in the logfile and you'll be able to track them down.


And for heaven's sake, RTFM and http://tinyurl.com/anel

--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

--- End Message ---
--- Begin Message ---
On 4/1/06, Benjamin D Adams <[EMAIL PROTECTED]> wrote:
> I'm trying to check a string for ../
> <?php
>         if(preg_match("/..//i", $string)){
>                 echo "string has ../";
>         }
> ?>
>
> Can't get it to work can anyone help?

Since / is your delimiter you need to escape it.

Also '.' means anything so you need to escape that as well.

if (preg_match('/\.\.\//', $string)) ...

What are you trying to achieve? There may be a better way than using a
regular expression.

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

--- End Message ---
--- Begin Message ---
Chr     is wrote:
You're right, it's not going through the __Set() method a second time.

If you REALLY want to get confused by overloading behavior try the following code using your T class:

$t = new T;

$t->insideArray = array('a' => 'A', 'b' => 'B', 'c' => 'C');

foreach ($t->insideArray as $k => $v) {
    $t->insideArray[$k] = null;
}

if (count($t->insideArray) > 0) {
    foreach ($t->insideArray as $k => $v) {
        echo $v;
    }
}

var_dump($t);

Why does count() return > 0?

Why has $t->insideArray become NULL instead of an empty array?

I can't tell you because I don't have access to a 5.1.2 CLI at the moment.
I can tell you that this leads to a SegFault on 5.0.4, here is the output:

Setting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Segmentation fault

and on 5.1.1 it's not much better, the output is:

Setting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
Getting insideArray
FATAL:  emalloc():  Unable to allocate 1916888421 bytes



Chris
[EMAIL PROTECTED]



On Mar 31, 2006, at 7:39 PM, Jochem Maas wrote:

could you both take a look at this (I posted it already btw) - notice that the second 'set' action ($t->insideArray["test"] = "testing!";) is not going via __set() at all, it uses __get() BUT/AND then an item is set in the returned array ... and also in the [sub] array stored inside the object (even though
nothing is being returned by reference):

(I feel that this is not right somehow!)

<?php

class T {

    private $array = array();

    public function __get( $key ) {
    echo "Getting $key\n";
        return $this->array[$key];
    }

    public function __set( $key, $value ) {
    echo "Setting $key\n";
        $this->array[$key] = $value;
    }

}

$t = new T;

$t->insideArray = array();
$t->insideArray["test"] = "testing!";

var_dump( $t );

?>

OUTPUT:

Setting insideArray
Getting insideArray
object(T)#1 (1) {
  ["array:private"]=>
  array(1) {
    ["insideArray"]=>
    array(1) {
      ["test"]=>
      string(8) "testing!"
    }
  }



Jasper Bryant-Greene wrote:

Jim Lucas wrote:

Jasper Bryant-Greene wrote:

Jochem Maas wrote:

[snip]

you guess wrong :-)  .. I couldn't resist testing it:

php -r '
class T { private $var = array();
function __set($k, $v) { $this->var[$k] = $v; }
function __get($k)     { var_dump($k); }
}
$t = new T;
$t->arr = array();
$t->arr["a"] = 1;
echo "OUTPUT: \n"; var_dump($t->arr); var_dump($t->arr["a"]); var_dump($t);
'


[snip]

Code:

<?php

class T {

    private $array = array();

    public function __get( $key ) {
        return $this->array[$key];
    }

    public function __set( $key, $value ) {
        $this->array[$key] = $value;
    }

}

$t = new T;

$t->insideArray = array();
$t->insideArray['test'] = 'testing!';

var_dump( $t );

?>

Output:

object(T)#1 (1) {
  ["array:private"]=>
  array(1) {
    ["insideArray"]=>
    array(1) {
      ["test"]=>
      string(8) "testing!"
    }
  }
}

Dont know if you guys see the MAJOR difference between your code, so I will point it out.

Jasper did this

function __get($k)     {
   var_dump($k);
}

Uhm, no I didn't. Jochem did :)

Jochem did this

public function __get( $key ) {
  return $this->array[$key];
}

No, I did that.

First off, the required public before the function call was not included, secondly, Jasper is var_dumping the key of the array, not the array it self.

Public is not required. I always put it regardless, but if you leave it off then PHP defaults to public for compatibility reasons. Jochem's code, which behaves incorrectly, does var_dump. Mine just returns the array key as you would expect. That's why Jochem's doesn't behave correctly with arrays.





--- End Message ---
--- Begin Message ---
why is this iconv function not working for me?  
i am converting $search to euc-kr charset.....
my conversion code is not working.

background and motivation
--------------------
i       have to mimic a accept-charset on a form to fake a get request by
disguising it as a hyperlink.  (my firefox refuses me tosend a remote
post request from a win_open() [ al a javascript] function.

the accept-charset value is 'euc-kr'.

i threw in extra iconv_set_encoding to eliminate some problem there, but
still no progress... :(

code
----------
$xab = 1;
$str_out =  mb_detect_encoding($search);
$converted_search="ax";
iconv_set_encoding("output_encoding", "EUC-KR");
iconv_set_encoding("input_encoding", $str_out);
if ($xab) echo " mb_detect_encoding***" . $str_out ."***search***
$search***<br>";
if ( function_exists('iconv') )   {
    if ($str_out != 'euc-kr') {
        if ($xab) var_dump( iconv_get_encoding('all'));
        if ($xab) echo "iconv: \$converted_search***$converted_search***
<br>";
        $converted_search = iconv($str_out,"EUC-KR",$search);
        if ($xab) echo "iconv: \$converted_search***$converted_search***
<br>";
    }
}


output (checks that search is proper and outputs "iconv_detect_encoding"
and checks return from iconv function call)
-----
mb_detect_encoding***UTF-8***search***꺼다***
array(3) { ["input_encoding"]=> string(5) "UTF-8" ["output_encoding"]=>
string(6) "EUC-KR" ["internal_encoding"]=> string(10) "ISO-8859-1" }
iconv: $converted_search***ax*** 
iconv: $converted_search******

many blessings to all.
merry chirstmas.

--- End Message ---
--- Begin Message ---
> why is this iconv function not working for me?  
> i am converting $search to euc-kr charset.....
> my conversion code is not working.
> 
> background and motivation
> --------------------
> i     have to mimic a accept-charset on a form to fake a get request by
> disguising it as a hyperlink.  (my firefox refuses me tosend a remote
> post request from a win_open() [ al a javascript] function.
> 
> the accept-charset value is 'euc-kr'.
> 
> i threw in extra iconv_set_encoding to eliminate some problem there, but
> still no progress... :(
> 
> code
> ----------
> $xab = 1;
> $str_out =  mb_detect_encoding($search);
> $converted_search="ax";
> iconv_set_encoding("output_encoding", "EUC-KR");
> iconv_set_encoding("input_encoding", $str_out);
> if ($xab) echo " mb_detect_encoding***" . $str_out ."***search***
> $search***<br>";
> if ( function_exists('iconv') )   {
>     if ($str_out != 'euc-kr') {
>         if ($xab) var_dump( iconv_get_encoding('all'));
>         if ($xab) echo "iconv: \$converted_search***$converted_search***
> <br>";
>         $converted_search = iconv($str_out,"EUC-KR",$search);
>         if ($xab) echo "iconv: \$converted_search***$converted_search***
> <br>";
>     }
> }
> 
> 
> output (checks that search is proper and outputs "iconv_detect_encoding"
> and checks return from iconv function call)
> -----
> mb_detect_encoding***UTF-8***search***꺼다***
> array(3) { ["input_encoding"]=> string(5) "UTF-8" ["output_encoding"]=>
> string(6) "EUC-KR" ["internal_encoding"]=> string(10) "ISO-8859-1" }
> iconv: $converted_search***ax*** 
> iconv: $converted_search******
> 
> many blessings to all.
> merry chirstmas.

this works for some utf8 words coming in.
strange, also, if i var_dump($converted_search) it says
---->    string(4) ""
but it is completely empty for all other purposes.

by the way, is this the correct way to send an encoded value over the
internet for a href tag, as a get request?

the $converted_search is what is output from the iconv functions....

<center><h3>search from <a
href='http://nlpweb.kaist.ac.kr/Urimal/find_word.php?kt_word=\";<?php
echo
$converted_search; 
?>\"&cs=ksc'>http://nlpweb.kaist.ac.kr/Urimal/</a></h3></center>

--- End Message ---
--- Begin Message ---
Hi there,

I am trying to encode output with php with uft8_encode(); and then output it to an xml file. Unfortunatelly this does not work as the string that has been encoded by utf8_encode is not valid utf8?!

Any ideas how this has happened?

Here is a link to this file:
http://www.findix.com/syndication/listing_autos.xml

Thank you for any hint,

Merlin

--- End Message ---
--- Begin Message ---
Hi,

Anyone can suggest me which PHP AJAX framework you are using, for what 
reason(s), what are pros and cons of your particular choice.

I found many, and now facing difficult choice.

BTW, how do you pass session id between calls to PHP from JavaScript (cookies 
or explicit foo.php?PHPSESSSIONID=blahblahblah)?

Thanks in advance for any suggestion(s).

Andrei

--- End Message ---
--- Begin Message ---
Andrei Verovski (aka MacGuru) wrote:
> Hi,
> 
> Anyone can suggest me which PHP AJAX framework you are using, for what 
> reason(s), what are pros and cons of your particular choice.
> 
> I found many, and now facing difficult choice.
> 
> BTW, how do you pass session id between calls to PHP from JavaScript (cookies 
> or explicit foo.php?PHPSESSSIONID=blahblahblah)?
> 
> Thanks in advance for any suggestion(s).

http://pear.php.net/HTML_AJAX

The setup is simple, usage is very easy to debug and it is actively
maintained by one of the more respected PHP coders, Josh Eichorn.

Cookies are fully supported and are preferrable to using a GET variable.

Greg

--- End Message ---
--- Begin Message ---
 > > > I always close the connection right after my
 > > query -- force of habit. It's like leaving the
 > > toilet seat up, it's only going to get you into
 > > trouble.
 >
 > So you close it after every query and then re-open it later for the
 > next query? I don't see that as a good idea.
 > >
 > No, you leave it open until you're done with the database.

Reading Ted's post didn't give this impression. I wanted to make sure
he wasn't doing it that way.

Chris et al:

Actually I am. When I need something from the dB, I open it, get the information and close it. It's like opening a drawer, getting what you need, and then closing the drawer. Where's the problem?

I don't see any reason whatsoever for me to open the dB at the start of my session and then close it at the end. Is there some overwhelming reason for anyone to do so?

You see, my habit stems from doing a lot of communication programming -- it was my experience that you open a communication port (file/channel/port/whatever); establish a link; exchange data; and close it. There's no need to leave it open.

Additionally, isn't that they way the net is set up? When your browser accesses a web site, the browser sends a request for information, the web site responds, and then both of you attend to your own business. There is no maintaining an open communication link, other than a session or cookie.

Plus, if you are talking to several devices (including dB's) at once, then how do you know for sure which device you're talking to IF you leave all communication ports open?

Furthermore, from a code perspective, I always comment my open and close dB-includes as a pair -- like braces in a function or in an "if statement". That way, I always know where in my code are the dB segments. Additionally, I also number the error statements in the die portion -- so if something goes wrong, I know exactly where it went wrong.

This does not mean that I place an open/extract-insert/close dB within a loop. If I need to get something that way, then I open the dB before the loop and close the dB after the loop. However, I much prefer having MySQL do the looping for me.

It's my understanding that opening a dB isn't problematic and isn't something that I should worry about, right? It's also my understanding that opening a dB is very fast, and it can manage a large number of commands, and different connections very quickly, right? Then what's the problem with opening it several times during a session instead just once?

If someone cares to enlighten me with a convincing argument to do otherwise, I'll certainly consider and adapt. But my guess is, that opening a dB the way I do it presents no significant downside.

I've never had a problem with showing my ignorance before, so prove me wrong if you can. I can learn.

Thanks.

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---

Reply via email to