Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    135
    Thanks
    13
    Thanked 10 Times in 10 Posts

    class variable not letting me use fullstop

    hi there, i'am having a problem with using the the fullstop to concat 2 stings in a class variable.

    PHP Code:
    define("TEST""hello");

    class 
    myclass
    {
        var 
    $myvar TEST "world";

    is there any reason why the above wouldnt work? if so how would i get around it?

    i get an error but i am using an IIS server and for some reason it wont let me turn on php errors. sorry.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    You can't use an expression or return value of a function to a class member while decalration. You'd need to move that code into constructor, like
    PHP Code:
    class myclass
    {
        var 
    $myvar;
       function 
    __construct(){
       
    $this->myvar=TEST "world"
       }

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    mike182uk (01-23-2010)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    This doesn't work no matter what server you use. You can't concatenate strings when defining properties of a class
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Regular Coder
    Join Date
    May 2008
    Posts
    135
    Thanks
    13
    Thanked 10 Times in 10 Posts
    hey abduraooft thanks alot for that, i thought i was just making a syntax error, i didnt even know about the constructor. anyways thanks alot that worked great! i'll go and read up on constructors


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •