$this->delimiter in php explode [message #177718] |
Tue, 17 April 2012 01:45 |
j
Messages: 9 Registered: July 2011
Karma: 0
|
Junior Member |
|
|
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
function?
Jeff
|
|
|
Re: $this->delimiter in php explode [message #177719 is a reply to message #177718] |
Tue, 17 April 2012 02:08 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 4/16/2012 9:45 PM, j wrote:
> 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
> function?
>
> Jeff
>
>
The following code works fine here.
<?php
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();
$mc->myfunc();
?>
$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.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: $this->delimiter in php explode [message #177720 is a reply to message #177718] |
Tue, 17 April 2012 07:26 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
Am 17.04.2012 03:45, schrieb j:
> 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 function?
>
> Jeff
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"?
/Str.
|
|
|