Solved

casting object of closure to string?

Posted on 2014-12-28
6
80 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

821 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