$this->delimiter in php explode

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
   I've written a function in a class

public $delimiter = ';';


public function some_function(){
    echo $this->delimiter; // yields: ;
    $SOME_ARRAY= explode($this->delimiter,$some_string);

    echo $this->delimiter // yields: 1

So,  running explode changes the value of the class variable $delimiter.
It's obvious I'm stepping on something, but I'm not sure what other than
there is a delimiter in explode. What does $this mean inside the explode


Re: $this->delimiter in php explode

On 4/16/2012 9:45 PM, j wrote:
Quoted text here. Click to load it

The following code works fine here.


class MyClass {
   private $delimiter = ';';

   public function myfunc() {
     $str = 'abd;def;ghi';
     echo $this->delimiter . "\n";
     $arr = explode($this->delimiter, $str);
     echo $this->delimiter . "\n";

$mc = new MyClass();

$this in the explode() function means the same thing it does anywhere
else - it is referencing the object the function is a member of.  In
this case it says you want the $delimiter member of the object (instead
of some other $delimiter variable).

I suspect your problem is somewhere else.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: $this->delimiter in php explode

Am 17.04.2012 03:45, schrieb j:
Quoted text here. Click to load it

The error must be outside the shown code, as is the case with setting of
$some_string. The parameters here are okay.

Maybe just do a string search on "delimiter"?


Site Timeline