|
List Info
Thread: Class Construction in PHP
|
|
| Class Construction in PHP |

|
2007-05-24 08:29:12 |
|
Hello,
I use the following commands to work with arrays: $array = array("Test" => 123,
"Abc" => 456);
//Extract array values into vars with the same name of the keys in lower case extract(array_change_key_case($array, CASE_LOWER), EXTR_PREFIX_SAME, "");
However, i'd like to do this using a OO Class (I'm a begginer in OO).
So, i do this:
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER),
EXTR_PREFIX_SAME, "");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |

|
2007-05-24 10:03:12 |
|
$arr = new CArray($array);
On 5/24/07, Ralph Rassweiler < ralphrass gmail.com">ralphrass gmail.com> wrote:
Hello,
I use the following commands to work with arrays: $array = array("Test" => 123,
"Abc" => 456);
//Extract array values into vars with the same name of the keys in lower case extract(array_change_key_case($array, CASE_LOWER), EXTR_PREFIX_SAME, "");
However, i'd like to do this using a OO Class (I'm a begginer in OO).
So, i do this:
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER),
EXTR_PREFIX_SAME, "");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
-- Sem mais para o momento, Rodrigo Souza
-------------------------------------------------------------------------------- :: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |
  Costa Rica |
2007-05-24 10:03:35 |
|
You don’t have a constructor, in PHP the constructors
syntax are something like this:
Class CArray{
Var $Array;
function
__construct($arr){
$this->Array
= $arr;
}
...
It’s different of java
;)
--
Wilkin
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME,
"");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |

|
2007-05-24 11:26:38 |
|
Hey,
I use the constructor "__construct", but no good:
class CArray { var $Array; function __construct($arr) { $this->Array = $arr; }
function Extract() { extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME, ""); } }
$ar = new CArray($array); $ar->Extract();
What's wrong?
On 5/24/07, Wilkin Melendez < wilkin wmelendez.com">wilkin wmelendez.com> wrote:
You don't have a constructor, in PHP the constructors
syntax are something like this:
Class CArray{
Var $Array;
function
__construct($arr){
$this->Array
= $arr;
}
...
It's different of
java
;)
--
Wilkin
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME,
"");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |

|
2007-05-24 12:17:20 |
|
"function CArray($arr)" == "function __construct($arr
)" but "function __construct($arr
)" work only in PHP 5
The problem was only that Array does not exist in PHP!!!!!!!!!
On 5/24/07, Ralph Rassweiler < ralphrass gmail.com">ralphrass gmail.com> wrote:
Hey,
I use the constructor "__construct", but no good:
class CArray { var $Array; function __construct($arr) { $this->Array = $arr;
}
function Extract() { extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME, ""); } }
$ar = new CArray($array);
$ar->Extract();
What's wrong?
On 5/24/07, Wilkin Melendez < wilkin wmelendez.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
wilkin wmelendez.com> wrote:
You don't have a constructor, in PHP the constructors
syntax are something like this:
Class CArray{
Var $Array;
function
__construct($arr){
$this->Array
= $arr;
}
...
It's different of
java
;)
--
Wilkin
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME,
"");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
-- Sem mais para o momento, Rodrigo Souza
-------------------------------------------------------------------------------- :: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |

|
2007-05-24 12:21:59 |
|
SORRY!!!!
"function CArray($arr)" == "function __construct($arr
)" both equals function both notations function
but "function __construct($arr
)" work only in PHP 5
The problem was only that
"new Array" does not exist in PHP!!!!!!!!!
On 5/24/07, Rodrigo Souza < rodrigosouzadossantos gmail.com">
rodrigosouzadossantos gmail.com> wrote:"function CArray($arr)" == "function __construct(
$arr
)" but "function __construct($arr
)" work only in PHP 5
The problem was only that Array does not exist in PHP!!!!!!!!!
On 5/24/07, Ralph Rassweiler < ralphrass gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">ralphrass gmail.com> wrote:
Hey,
I use the constructor "__construct", but no good:
class CArray { var $Array; function __construct($arr) { $this->Array = $arr;
}
function Extract() { extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME, ""); } }
$ar = new CArray($array);
$ar->Extract();
What's wrong?
On 5/24/07, Wilkin Melendez < wilkin wmelendez.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
wilkin wmelendez.com> wrote:
You don't have a constructor, in PHP the constructors
syntax are something like this:
Class CArray{
Var $Array;
function
__construct($arr){
$this->Array
= $arr;
}
...
It's different of
java
;)
--
Wilkin
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME,
"");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
-- Sem mais para o momento, Rodrigo Souza
--------------------------------------------------------------------------------
:: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
-- Sem mais para o momento, Rodrigo Souza
-------------------------------------------------------------------------------- :: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |

|
2007-05-24 12:25:37 |
|
Sorry, i don't get it.
I';m Using PHP 5.1.4.
On 5/24/07, Rodrigo Souza < rodrigosouzadossantos gmail.com">rodrigosouzadossantos gmail.com
> wrote:SORRY!!!!
"function CArray($arr)" == "function __construct(
$arr
)" both equals function both notations function
but "function __construct($arr
)" work only in PHP 5
The problem was only that
"new Array" does not exist in PHP!!!!!!!!!
On 5/24/07,
Rodrigo Souza < rodrigosouzadossantos gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
rodrigosouzadossantos gmail.com> wrote:"function CArray($arr)" == "function __construct(
$arr
)" but "function __construct($arr
)" work only in PHP 5
The problem was only that Array does not exist in PHP!!!!!!!!!
On 5/24/07, Ralph Rassweiler < ralphrass gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">ralphrass gmail.com> wrote:
Hey,
I use the constructor "__construct", but no good:
class CArray { var $Array; function __construct($arr) { $this->Array = $arr;
}
function Extract() { extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME, ""); } }
$ar = new CArray($array);
$ar->Extract();
What's wrong?
On 5/24/07, Wilkin Melendez < wilkin wmelendez.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
wilkin wmelendez.com> wrote:
You don't have a constructor, in PHP the constructors
syntax are something like this:
Class CArray{
Var $Array;
function
__construct($arr){
$this->Array
= $arr;
}
...
It's different of
java
;)
--
Wilkin
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array, CASE_LOWER), EXTR_PREFIX_SAME,
"");
}
}
$arr = new Array($array);
$arr->Extract();
Nothing happend... not even an error. What is wrong in this class?
-- "Omnia si perdas, famam servare memento"
-- Sem mais para o momento, Rodrigo Souza
--------------------------------------------------------------------------------
:: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
-- Sem mais para o momento, Rodrigo Souza
-------------------------------------------------------------------------------- :: Rodrigo Souza dos Santos
:: Curitiba - Paraná - Brasil :: rodrigosouzadossantos gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rodrigosouzadossantos gmail.com --------------------------------------------------------------------------------
-- "Omnia si perdas, famam servare memento"
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| Re: Class Construction in PHP |
  United States |
2007-05-25 04:23:51 |
Hi,
your code should work, but what are you tryin to do?
The content of class property $this->Array will be
extracted inside
the function Extract(). Therefore the new variables $test
and $abc
only available inside the function Extract(). You can test
this by
using get_defined_vars(). Example:
[snip]
$array = array("Test" => 123, "Abc"
=> 456);
class CArray {
var $Array;
function CArray($arr) {
$this->Array = $arr;
}
function Extract() {
extract(array_change_key_case($this->Array,
CASE_LOWER),
EXTR_PREFIX_SAME, "");
$vars = get_defined_vars();
var_dump($vars);
}
}
$arr = new CArray($array);
$arr->Extract();
[/snap]
__construct() vs. CArray():
You should use __construct() as constructor instead of
CArray(). Both
will work but __construct ist the better way. The PHP parser
(>= 5)
will look at first for an __construct() definition, after
then it
looks for an function having same name as the class.
purcaholic
On 24 Mai, 15:29, "Ralph Rassweiler"
<ralphr... gmail.com> wrote:
> Hello,
>
> I use the following commands to work with arrays:
> $array = array("Test" => 123,
> "Abc" => 456);
> //Extract array values into vars with the same name of
the keys in lower
> case
> extract(array_change_key_case($array, CASE_LOWER),
EXTR_PREFIX_SAME, "");
>
> However, i'd like to do this using a OO Class (I'm a
begginer in OO).
>
> So, i do this:
>
> class CArray {
> var $Array;
>
> function CArray($arr) {
> $this->Array = $arr;
> }
> function Extract() {
>
extract(array_change_key_case($this->Array, CASE_LOWER),
> EXTR_PREFIX_SAME, "");
> }
>
> }
>
> $arr = new Array($array);
> $arr->Extract();
>
> Nothing happend... not even an error. What is wrong in
this class?
>
> --
> "Omnia si perdas, famam servare memento"
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers"
group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Class Construction in PHP |
  United States |
2007-06-05 03:11:58 |
$arr = new CArray ($array);
extract ($arr->getVars ());
instead of Extract():
function getVars ()
{
return $this->Array;
}
--
free web developer tools:
http://osbtools.goog
lepages.com/
On May 25, 11:23 am, purcaholic <purcaho... googlemail.com> wrote:
> Hi,
>
> your code should work, but what are you tryin to do?
>
> The content of class property $this->Array will be
extracted inside
> the function Extract(). Therefore the new variables
$test and $abc
> only available inside the function Extract(). You can
test this by
> using get_defined_vars(). Example:
> [snip]
> $array = array("Test" => 123,
"Abc" => 456);
>
> class CArray {
> var $Array;
>
> function CArray($arr) {
> $this->Array = $arr;
> }
>
> function Extract() {
>
extract(array_change_key_case($this->Array, CASE_LOWER),
> EXTR_PREFIX_SAME, "");
> $vars = get_defined_vars();
> var_dump($vars);
> }
>
> }
>
> $arr = new CArray($array);
> $arr->Extract();
> [/snap]
>
> __construct() vs. CArray():
> You should use __construct() as constructor instead of
CArray(). Both
> will work but __construct ist the better way. The PHP
parser (>= 5)
> will look at first for an __construct() definition,
after then it
> looks for an function having same name as the class.
>
> purcaholic
>
> On 24 Mai, 15:29, "Ralph Rassweiler"
<ralphr... gmail.com> wrote:
>
> > Hello,
>
> > I use the following commands to work with arrays:
> > $array = array("Test" => 123,
> > "Abc" => 456);
> > //Extract array values into vars with the same
name of the keys in lower
> > case
> > extract(array_change_key_case($array, CASE_LOWER),
EXTR_PREFIX_SAME, "");
>
> > However, i'd like to do this using a OO Class (I'm
a begginer in OO).
>
> > So, i do this:
>
> > class CArray {
> > var $Array;
>
> > function CArray($arr) {
> > $this->Array = $arr;
> > }
> > function Extract() {
> >
extract(array_change_key_case($this->Array, CASE_LOWER),
> > EXTR_PREFIX_SAME, "");
> > }
>
> > }
>
> > $arr = new Array($array);
> > $arr->Extract();
>
> > Nothing happend... not even an error. What is
wrong in this class?
>
> > --
> > "Omnia si perdas, famam servare
memento"
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers"
group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
[1-9]
|
|