Solved

casting object of closure to string?

Posted on 2014-12-28
6
75 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

23 Experts available now in Live!

Get 1:1 Help Now