This is a discussion on PHP 4 OOP, re-using a object? within the PHP General forums, part of the PHP Programming Forums category; Hi, I am slowly learning how to use classes properly... quick question: # Create the object: $doSplash = new RandomSplash(); // Create the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I am slowly learning how to use classes properly... quick question: # Create the object: $doSplash = new RandomSplash(); // Create the object. Shouldn't I be able to call that object like below, throughout my page: ....HTML... <?php $doSplash->randomize('css'); ?> ....HTML... <?php $doSplash->randomize('xhtml top'); ?> ....HTML... <?php $doSplash->randomize('xhtml bot'); ?> ....HTML... Sorry, this is probably a noob question... I am pretty good at using functions, but classes are still new to me. Any help, even a RTFM link, would be really appreciated. :) Have a great day! Cheers, Micky -- Wishlist: <http://snipurl.com/vrs9> Switch: <http://browsehappy.com/> BCC?: <http://snipurl.com/w6f8> My: <http://del.icio.us/mhulse> |
|
|||
|
Micky Hulse wrote:
> Hi, > > I am slowly learning how to use classes properly... quick question: > > # Create the object: > $doSplash = new RandomSplash(); // Create the object. > > Shouldn't I be able to call that object like below, throughout my page: > > ...HTML... > <?php $doSplash->randomize('css'); ?> > ...HTML... > <?php $doSplash->randomize('xhtml top'); ?> > ...HTML... > <?php $doSplash->randomize('xhtml bot'); ?> > ...HTML... > > Sorry, this is probably a noob question... I am pretty good at using > functions, but classes are still new to me. > > Any help, even a RTFM link, would be really appreciated. :) > > Have a great day! > Cheers, > Micky you should be able to, and it works fine for me. www.php.net/oop will help, if you haven't read it. - tul |
|
|||
|
Micky Hulse wrote:
> Any help, even a RTFM link, would be really appreciated. :) Hi all, A fellow list member gave answered my question off-list and pointed me here: http://www.php.net/oop Going to (re)read... It has been a while since I last worked with classes. :) I asked because I was getting an error with my code... I thought it was how I was calling it. Anyway, have a great day, Cheers, Micky -- Wishlist: <http://snipurl.com/vrs9> Switch: <http://browsehappy.com/> BCC?: <http://snipurl.com/w6f8> My: <http://del.icio.us/mhulse> |
|
|||
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Micky Hulse wrote: > Micky Hulse wrote: >> Any help, even a RTFM link, would be really appreciated. :) > > Hi all, > > A fellow list member gave answered my question off-list and pointed me > here: > > http://www.php.net/oop > > Going to (re)read... It has been a while since I last worked with > classes. :) > > I asked because I was getting an error with my code... I thought it was > how I was calling it. > > Anyway, have a great day, > Cheers, > Micky > > What's the error, and how do you have the class and functions defined? - -- Christopher Weldon, ZCE President & CEO Cerberus Interactive, Inc. cweldon@cerberusonline.com 979.739.5874 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFBMjMZxvk7JEXkbERArjTAKCVd57A8Pj+aoaY0iF4BU/5A1dmawCeP3ku h4bOmUAeBphVXvOfnnpOwUQ= =JPWQ -----END PGP SIGNATURE----- |
|
|||
|
Christopher Weldon wrote:
> What's the error, and how do you have the class and functions defined? Hi Christopher, thanks for asking. :) Actually, it was one of those silly, right in front of my face, logic errors... class RandomSplash { var $alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'); function randomize($what) { switch($what) { case 'css': $data = $this->$alphabet; ... ... ... } } See the error? $data = $this->$alphabet; should've been: $data = $this->alphabet; At first I thought it was how I was calling the class... all works now though. :) Thanks for asking. Let me know if you see a better way to do the above though, I am pretty new to using classes, but I am pretty handy when it comes to functions. :D Thanks, Cheers, Micky -- Wishlist: <http://snipurl.com/vrs9> Switch: <http://browsehappy.com/> BCC?: <http://snipurl.com/w6f8> My: <http://del.icio.us/mhulse> |
|
|||
|
On 9/10/06, Micky Hulse <micky@ambiguism.com> wrote:
> Christopher Weldon wrote: > > What's the error, and how do you have the class and functions defined? > > Hi Christopher, thanks for asking. :) > > Actually, it was one of those silly, right in front of my face, logic > errors... > > class RandomSplash { > var $alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', > 'k', 'l', 'm'); > function randomize($what) { > switch($what) { > case 'css': > $data = $this->$alphabet; > ... > ... > ... > } > } > > See the error? For future reference it is best you provide a full code example in what your problem is when you ask the question, Asking if it something is proper isn't going to get you far. <?php echo $am_somevar; ?> is perfectly valid but accoring to the mistake you had you should have been using: <?php echo $I_am_somevar;?> It would have been more relevant to supply the problem along with the solution. > > $data = $this->$alphabet; > > should've been: > > $data = $this->alphabet; > > At first I thought it was how I was calling the class... all works now > though. :) Good to hear you got it resolved.. Curt. |
|
|||
|
Hi Curt, thanks for the feedback/input and your time. :)
Curt Zirzow wrote: > It would have been more relevant to supply the problem along with the > solution. Definitely. Sorry about that. Sometimes I post questions to forums/lists without thinking things through more thoroughly... Hehe, I half blame that on sleep deprivation and half on ADD. Lol, or something. :) I will be sure to take your advice into account for my future posts to this and other lists. Thanks again. Have a great day. Cheers, Micky -- Wishlist: <http://snipurl.com/vrs9> Switch: <http://browsehappy.com/> BCC?: <http://snipurl.com/w6f8> My: <http://del.icio.us/mhulse> |
|
|||
|
On 9/11/06, Micky Hulse <micky@ambiguism.com> wrote:
> Hi Curt, thanks for the feedback/input and your time. :) > > Curt Zirzow wrote: > > It would have been more relevant to supply the problem along with the > > solution. > > Definitely. Sorry about that. Sometimes I post questions to forums/lists > without thinking things through more thoroughly... Hehe, I half blame > that on sleep deprivation and half on ADD. Lol, or something. :) No problems at all. I just noticed that the question you originally proposed couldn't really be solved without more info other wise everyone would be guessing at what the issue is.. And in the end you solved your own problem. It is a common thing to do such a thing, i tend to practice this method of posting questions to ensure i provide enough information to solve the issue: 1) compose a question 2) forget the question was about and read the question, and see if it is even able to be solved. 3) if it cant be solved, include a statement like: I've been looking over this and can't see what I'm missing (type of thing). Curt. > > I will be sure to take your advice into account for my future posts to > this and other lists. heh.. now you have more advice to consider.. :) > > Thanks again. Have a great day. No problem. Curt. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|