|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Class public variable giving
PHP Code:
Trying to execute this simple function to make sure my syntax is correct before pulling phrases from mysql, but keep getting a unexpected T_VARIABLE syntax error on the execution of the public setting. Last edited by PiMPaRSeBiSh : May 4th, 2008 at 12:26 AM. Reason: removed quotes from $value |
|
#2
|
|||
|
|||
|
My experience in classes is limited, however, I notice you do not have a constructor. And in the foreach, do you want the var $value in quotes?
|
|
#3
|
|||
|
|||
|
No, don't want the var in quotes, just forgot to remove them before posting. I had tried several variations before posting here, one of which wrapped the var in quotes. As for the constructor, I'm not looking to link any functions, only to call the variable via $info->phrase['network'].
|
|
#4
|
|||
|
|||
|
Quote:
Are you still getting the error message without the quotes around the variable? If so, does your message say which line is causing the error to trigger? Also, it seems you could get by without the class and use the function, which may be more efficient. |
|
#5
|
|||
|
|||
|
Yes, it still gives the error without the quotes. This is the first way I tried. The line of error is 'public $key = $value;'. The class will bcome much more advanced, pulling info from mysql and the such. I just want to make sure it works before adding the more advanced modules.
|
|
#6
|
|||
|
|||
|
Quote:
Maybe the problem lies in your declaring the var public in the foreach. The var should be declared outside the function and the foreach (public $value; ) and the foreach should be left to process whatever you want to do if the conditions of the foreach are met. |
|
#7
|
|||
|
|||
|
I got it to work with var, instead of public. thanks though.
|
|
#8
|
|||
|
|||
|
Quote:
Good deal. However, you will need to declare variables within the class before you get into functions and such, or you may start getting more errors, especially as your class begins to grow and extend. Hope this is helpful. |
|
#9
|
|||
|
|||
|
This is understood. Only problem I am having now is a nesting a classes. For example, having the main class and a couple classes inside (each having several of their own functions), one for db handling, one for template handling, and another for phrase handling. $class->subclass->function() Is this possible?
|
|
#10
|
|||
|
|||
|
Quote:
Classes don't nest. A subclass is a child of a parent class. It is a separate class but inherits from the parent. |
|
#11
|
|||
|
|||
|
So how would I implement this? I'm looking to do something like this:
PHP Code:
So I can call: $site->cache->phrases to cache phrases $site->cache->templates to cache templates $site->db->connect to connect to the db $site->db->query to inject sql and of course $site->phrases will contain the array of phrases from the db. |
|
#12
|
|||
|
|||
|
Quote:
The db connect class would be a stand alone class; not a parent or a child to the other two classes. I am not sure how these other classes are going to function in your code, but by first impressions, I would say the cache class would also be a stand alone class. My knowledge of classes is limited as I, too, am a novice at implementing them, so I am not the one to give you in-depth instruction on this matter and without knowing exactly what you are doing, I can't draw up examples. However, these are basic principles I am relating. You might want to do a little more study on class implementation. Sorry, I can't be more helpful on this matter. Maybe in another month or two - if you want to wait that long!!! |
|
#13
|
||||
|
||||
|
please note that using var in php5 is only supported for compatibility reasons and should be considered deprecated behavior.
while it is possible, i don't know that you should be dynamically assigning members to a class. instead if you want this type of flexibility you should store the dynamic elements in an array member of the class. for example PHP Code:
PHP Code:
__________________
Jeff Carouth's Homepage Accelerate Studio have i been exceptionally helpful today? feeling generous? |
|
#14 |