Solved

casting object of closure to string?

Posted on 2014-12-28
6
78 Views
Last Modified: 2014-12-29
Hello,

I have this function that returns an object, which i would like to turn into a string. Casting it returns an error. Please help?

$hehe =(string) (function() {
			echo '[';
			for ($j = 0; $j < 1; $j++) {
				echo '{';
				echo '"title":"All Day Event",';
				echo '"start":"2014-11-01",';
				echo '"end":"2014-11-01"';
				if ($j == 1-1){
			             echo '}';
			        }
               			else {
		        		echo '},';
			       	}

			}
			echo ']';
		});

Open in new window

0
Comment
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40521305
Where is the object that it returns?
0
 

Author Comment

by:NeverEndingFlashStories
ID: 40521319
Well, apparently when i do gettype($hehe)
$hehe is an object.

I kind of expected it to be a string.
By the way, my casting it as a (string) at the beginning returns an error
0
 
LVL 84

Expert Comment

by:ozo
ID: 40521345
What would you want the contents of the string to be?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:NeverEndingFlashStories
ID: 40521419
Ah i am trying to produce this :

$hehe =  '[
  {
    "title": "All Day Event",
    "start": "2014-11-01"
  },
  {
    "title": "Long Event",
    "start": "2014-11-07",
    "end": "2014-11-10"
  }]'

I just realized i may have used the wrong thing when i used echo...i should have used concatenate instead, maybe? I am new to php..
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40521572
Do you mean something like this?
$f = function($t,$s,$e){
            $str=      '[
';
            for ($j = 0; $j < 2; $j++) {
                  $str .= '  {
';
                  if ($j == 2-1){
                          $str .= '    "title":"'.$t.',
    "start": "'.$s.'",
    "end": "'.$e.'
  }';
                    }
                             else {
                        $str .= '    "title":"All Day Event",
';
                               $str .= '    "start":"2014-11-01",
';
                          $str .= '  },
';
                               }

                  }
                  $str .= ']';
             return $str;
};
$hehe=$f("Long Event","2014-11-07","2014-11-10");
echo $hehe;
0
 

Author Closing Comment

by:NeverEndingFlashStories
ID: 40523094
Yes ,

precisely. Thank you so much!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now